ruby-static-tracing 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ruby-static-tracing/version.rb +1 -1
  3. metadata +3 -39
  4. data/ext/ruby-static-tracing/lib/libstapsdt/Makefile +0 -76
  5. data/ext/ruby-static-tracing/lib/libstapsdt/example/demo.c +0 -42
  6. data/ext/ruby-static-tracing/lib/libstapsdt/src/asm/libstapsdt-x86_64.s +0 -14
  7. data/ext/ruby-static-tracing/lib/libstapsdt/src/dynamic-symbols.c +0 -41
  8. data/ext/ruby-static-tracing/lib/libstapsdt/src/dynamic-symbols.h +0 -34
  9. data/ext/ruby-static-tracing/lib/libstapsdt/src/errors.c +0 -30
  10. data/ext/ruby-static-tracing/lib/libstapsdt/src/errors.h +0 -8
  11. data/ext/ruby-static-tracing/lib/libstapsdt/src/hash-table.c +0 -27
  12. data/ext/ruby-static-tracing/lib/libstapsdt/src/hash-table.h +0 -3
  13. data/ext/ruby-static-tracing/lib/libstapsdt/src/libstapsdt.c +0 -208
  14. data/ext/ruby-static-tracing/lib/libstapsdt/src/libstapsdt.h +0 -66
  15. data/ext/ruby-static-tracing/lib/libstapsdt/src/sdtnote.c +0 -176
  16. data/ext/ruby-static-tracing/lib/libstapsdt/src/sdtnote.h +0 -46
  17. data/ext/ruby-static-tracing/lib/libstapsdt/src/section.c +0 -30
  18. data/ext/ruby-static-tracing/lib/libstapsdt/src/section.h +0 -21
  19. data/ext/ruby-static-tracing/lib/libstapsdt/src/shared-lib.c +0 -563
  20. data/ext/ruby-static-tracing/lib/libstapsdt/src/shared-lib.h +0 -46
  21. data/ext/ruby-static-tracing/lib/libstapsdt/src/string-table.c +0 -67
  22. data/ext/ruby-static-tracing/lib/libstapsdt/src/string-table.h +0 -28
  23. data/ext/ruby-static-tracing/lib/libstapsdt/src/util.c +0 -12
  24. data/ext/ruby-static-tracing/lib/libstapsdt/src/util.h +0 -6
  25. data/ext/ruby-static-tracing/lib/libstapsdt/tests/test-errors.c +0 -77
  26. data/ext/ruby-static-tracing/lib/libstapsdt/tests/test-memory-leaks.c +0 -25
  27. data/ext/ruby-static-tracing/lib/libusdt/Makefile +0 -168
  28. data/ext/ruby-static-tracing/lib/libusdt/test_mem_usage.c +0 -77
  29. data/ext/ruby-static-tracing/lib/libusdt/test_usdt.c +0 -87
  30. data/ext/ruby-static-tracing/lib/libusdt/usdt.c +0 -321
  31. data/ext/ruby-static-tracing/lib/libusdt/usdt.h +0 -65
  32. data/ext/ruby-static-tracing/lib/libusdt/usdt_dof.c +0 -126
  33. data/ext/ruby-static-tracing/lib/libusdt/usdt_dof_file.c +0 -290
  34. data/ext/ruby-static-tracing/lib/libusdt/usdt_dof_sections.c +0 -180
  35. data/ext/ruby-static-tracing/lib/libusdt/usdt_internal.h +0 -107
  36. data/ext/ruby-static-tracing/lib/libusdt/usdt_probe.c +0 -133
  37. data/ext/ruby-static-tracing/lib/libusdt/usdt_tracepoints_i386.s +0 -69
  38. data/ext/ruby-static-tracing/lib/libusdt/usdt_tracepoints_x86_64.s +0 -123
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4d849e0cedda5f5deaeeeffc28d29519c7eab872e1e8d92fda8368d8a39d295d
4
- data.tar.gz: 84d72bc3630a1299ed7536c528a7bf12f72ac157076bf63144400690432adcd0
3
+ metadata.gz: 72b529791f8107bbe464af7deb35b4135fafe439307e88ff6deb019ec056d266
4
+ data.tar.gz: e71c574619cbce9237b959949b7eac088facbccbd52a8e1d478f4c4fc45e2470
5
5
  SHA512:
6
- metadata.gz: 747545a76cd5f98365a277b96673d24d8a7d51b934273bd8d913dea2f32fd0a4064cb1b2b79ec2e9c3ab980ed4d7840a874022f107f3d9def48e0c2b1deeb82a
7
- data.tar.gz: f910d359ad45e9677a98a3913a240d9080f99ed44aef1c2164fb6abaf807c06f7c9dd03cc6fd8676b3d6af30f719460139f9782373f5c35d5795cb9cc743cfe3
6
+ metadata.gz: 3c13797239eeb12eab9529a9bcf854c42c633ea1cb1b918413b2cea1ae1a94d96890739ed573495d585c5949d0a6ad0c6c50469423567239f583545a1f0b57b4
7
+ data.tar.gz: a7e0db40c3b13c34344430af47dfc1a18929f36c95aa586436175d4243b9ae4c84664fdb0b8d95eb7dcb10142dccef506a408ee43e174ada8a0298ed21cf129d
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StaticTracing
4
- VERSION = '0.0.11'
4
+ VERSION = '0.0.12'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-static-tracing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dale Hamel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-13 00:00:00.000000000 Z
11
+ date: 2019-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unmixer
@@ -113,41 +113,6 @@ files:
113
113
  - ext/ruby-static-tracing/extconf.rb
114
114
  - ext/ruby-static-tracing/include/ruby_static_tracing.h
115
115
  - ext/ruby-static-tracing/lib/deps-extconf.rb
116
- - ext/ruby-static-tracing/lib/libstapsdt/Makefile
117
- - ext/ruby-static-tracing/lib/libstapsdt/example/demo.c
118
- - ext/ruby-static-tracing/lib/libstapsdt/src/asm/libstapsdt-x86_64.s
119
- - ext/ruby-static-tracing/lib/libstapsdt/src/dynamic-symbols.c
120
- - ext/ruby-static-tracing/lib/libstapsdt/src/dynamic-symbols.h
121
- - ext/ruby-static-tracing/lib/libstapsdt/src/errors.c
122
- - ext/ruby-static-tracing/lib/libstapsdt/src/errors.h
123
- - ext/ruby-static-tracing/lib/libstapsdt/src/hash-table.c
124
- - ext/ruby-static-tracing/lib/libstapsdt/src/hash-table.h
125
- - ext/ruby-static-tracing/lib/libstapsdt/src/libstapsdt.c
126
- - ext/ruby-static-tracing/lib/libstapsdt/src/libstapsdt.h
127
- - ext/ruby-static-tracing/lib/libstapsdt/src/sdtnote.c
128
- - ext/ruby-static-tracing/lib/libstapsdt/src/sdtnote.h
129
- - ext/ruby-static-tracing/lib/libstapsdt/src/section.c
130
- - ext/ruby-static-tracing/lib/libstapsdt/src/section.h
131
- - ext/ruby-static-tracing/lib/libstapsdt/src/shared-lib.c
132
- - ext/ruby-static-tracing/lib/libstapsdt/src/shared-lib.h
133
- - ext/ruby-static-tracing/lib/libstapsdt/src/string-table.c
134
- - ext/ruby-static-tracing/lib/libstapsdt/src/string-table.h
135
- - ext/ruby-static-tracing/lib/libstapsdt/src/util.c
136
- - ext/ruby-static-tracing/lib/libstapsdt/src/util.h
137
- - ext/ruby-static-tracing/lib/libstapsdt/tests/test-errors.c
138
- - ext/ruby-static-tracing/lib/libstapsdt/tests/test-memory-leaks.c
139
- - ext/ruby-static-tracing/lib/libusdt/Makefile
140
- - ext/ruby-static-tracing/lib/libusdt/test_mem_usage.c
141
- - ext/ruby-static-tracing/lib/libusdt/test_usdt.c
142
- - ext/ruby-static-tracing/lib/libusdt/usdt.c
143
- - ext/ruby-static-tracing/lib/libusdt/usdt.h
144
- - ext/ruby-static-tracing/lib/libusdt/usdt_dof.c
145
- - ext/ruby-static-tracing/lib/libusdt/usdt_dof_file.c
146
- - ext/ruby-static-tracing/lib/libusdt/usdt_dof_sections.c
147
- - ext/ruby-static-tracing/lib/libusdt/usdt_internal.h
148
- - ext/ruby-static-tracing/lib/libusdt/usdt_probe.c
149
- - ext/ruby-static-tracing/lib/libusdt/usdt_tracepoints_i386.s
150
- - ext/ruby-static-tracing/lib/libusdt/usdt_tracepoints_x86_64.s
151
116
  - ext/ruby-static-tracing/lib/post-extconf.rb
152
117
  - ext/ruby-static-tracing/linux/provider.c
153
118
  - ext/ruby-static-tracing/linux/provider.h
@@ -189,8 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
154
  - !ruby/object:Gem::Version
190
155
  version: '0'
191
156
  requirements: []
192
- rubyforge_project:
193
- rubygems_version: 2.7.6.2
157
+ rubygems_version: 3.0.3
194
158
  signing_key:
195
159
  specification_version: 4
196
160
  summary: USDT tracing for Ruby
@@ -1,76 +0,0 @@
1
-
2
- CC=gcc
3
- CFLAGS= -std=gnu11
4
- LDFLAGS=-lelf -ldl -Wl,-z,noexecstack
5
- VERSION=0.1.0
6
-
7
- PREFIX=/usr
8
-
9
- OBJECTS = $(patsubst src/%.c, build/lib/%.o, $(wildcard src/*.c))
10
- HEADERS = $(wildcard src/*.h)
11
-
12
- SOLINK = libstapsdt.so
13
- SONAME = libstapsdt.so.0
14
-
15
- all: out/libstapsdt.a out/$(SONAME)
16
-
17
- install:
18
- mkdir -p $(DESTDIR)$(PREFIX)/lib
19
- mkdir -p $(DESTDIR)$(PREFIX)/include
20
- cp out/$(SONAME) $(DESTDIR)$(PREFIX)/lib/$(SONAME)
21
- cp src/libstapsdt.h $(DESTDIR)$(PREFIX)/include/
22
- ln -s $(DESTDIR)$(PREFIX)/lib/$(SONAME) $(DESTDIR)$(PREFIX)/lib/$(SOLINK)
23
-
24
- uninstall:
25
- rm -f $(DESTDIR)$(PREFIX)/lib/$(SONAME)
26
- rm -f $(DESTDIR)$(PREFIX)/lib/$(SOLINK)
27
- rm -f $(DESTDIR)$(PREFIX)/include/libstapsdt.h
28
-
29
- build/lib/libstapsdt-x86_64.o: src/asm/libstapsdt-x86_64.s
30
- mkdir -p build
31
- $(CC) $(CFLAGS) -fPIC -c $^ -o $@
32
-
33
- build/lib/%.o: src/%.c $(HEADERS)
34
- mkdir -p build/lib/
35
- $(CC) $(CFLAGS) -fPIC -c $< -o $@
36
-
37
- out/libstapsdt.a: $(OBJECTS) build/lib/libstapsdt-x86_64.o
38
- mkdir -p out
39
- ar rcs $@ $^
40
-
41
- out/$(SONAME): $(OBJECTS) build/lib/libstapsdt-x86_64.o
42
- mkdir -p out
43
- $(CC) $(CFLAGS) -shared -Wl,-soname=$(SONAME) -o $@ $^ $(LDFLAGS)
44
-
45
- demo: all example/demo.c
46
- $(CC) $(CFLAGS) example/demo.c out/libstapsdt.a -o demo -Isrc/ $(LDFLAGS)
47
-
48
- test: all
49
- make -C ./tests/
50
-
51
- clean:
52
- rm -rf build/*
53
- rm -rf out/*
54
- make clean -C ./tests/
55
-
56
- lint:
57
- clang-tidy src/*.h src/*.c -- -Isrc/
58
-
59
- format:
60
- clang-tidy src/*.h src/*.c -fix -- -Isrc/
61
-
62
- docs:
63
- make -C ./docs/ html
64
-
65
- docs-server:
66
- cd docs/_build/html; python3 -m http.server;
67
-
68
- deb-pkg-setup:
69
- mkdir -p dist/libstapsdt-$(VERSION)/;
70
- git archive HEAD | gzip > dist/libstapsdt-$(VERSION).tar.gz;
71
- tar xvzf dist/libstapsdt-$(VERSION).tar.gz -C dist/libstapsdt-$(VERSION)/;
72
- cd dist/libstapsdt-$(VERSION); dh_make -l -c mit -y -f ../libstapsdt-$(VERSION).tar.gz;
73
- rm -rf dist/libstapsdt-$(VERSION)/debian/*.ex dist/libstapsdt-$(VERSION)/debian/*.EX dist/libstapsdt-$(VERSION)/debian/README.*
74
-
75
-
76
- .PHONY: all clear lint format build-tests docs install uninstall deb-pkg-setup
@@ -1,42 +0,0 @@
1
- #include <stdio.h>
2
- #include <stdlib.h>
3
- #include <unistd.h>
4
- #include <libstapsdt.h>
5
-
6
- int main( int argc, char *argv[] ) {
7
- SDTProvider_t *provider;
8
- SDTProbe_t **probes;
9
- int probesCount = 0;
10
- unsigned long long i=0;
11
- int j=0;
12
-
13
- if(argc < 3) {
14
- printf("usage: demo PROVIDER PROBE\n");
15
- return -1;
16
- }
17
-
18
- probesCount = argc - 2;
19
- probes = calloc(sizeof(SDTProvider_t *), probesCount);
20
-
21
- provider = providerInit(argv[1]);
22
- for (int idx = 0; idx < (probesCount); idx++) {
23
- probes[idx] = providerAddProbe(provider, argv[idx + 2], 2, uint64, int64);
24
- }
25
-
26
- if(providerLoad(provider) == -1) {
27
- printf("Something went wrong: %s\n", provider->error);
28
- return -1;
29
- }
30
-
31
- while(1) {
32
- printf("Firing probes...\n");
33
- for (int idx = 0; idx < probesCount; idx++) {
34
- printf("Firing probe [%d]...\n", idx);
35
- probeFire(probes[idx], i++, j--);
36
- }
37
- printf("Probe fired!\n");
38
- sleep(3);
39
- }
40
-
41
- return 0;
42
- }
@@ -1,14 +0,0 @@
1
- .text
2
-
3
- .align 4, 0x90
4
- .globl _funcStart
5
- .globl _funcEnd
6
-
7
- _funcStart:
8
- nop
9
- nop
10
- nop
11
- nop
12
- ret
13
- _funcEnd:
14
- nop
@@ -1,41 +0,0 @@
1
- #include "dynamic-symbols.h"
2
- #include "string-table.h"
3
- #include <libelf.h>
4
-
5
- DynamicSymbolTable *dynamicSymbolTableInit(StringTable *dynamicString) {
6
- DynamicSymbolTable *dynSymTab =
7
- (DynamicSymbolTable *)calloc(sizeof(DynamicSymbolTable), 1);
8
-
9
- dynSymTab->stringTable = dynamicString;
10
-
11
- dynSymTab->bssStart.string = stringTableAdd(dynamicString, "__bss_start");
12
- dynSymTab->eData.string = stringTableAdd(dynamicString, "_edata");
13
- dynSymTab->end.string = stringTableAdd(dynamicString, "_end");
14
-
15
- dynSymTab->count = 0;
16
- dynSymTab->symbols = NULL;
17
-
18
- return dynSymTab;
19
- }
20
-
21
- DynamicSymbol *dynamicSymbolTableAdd(DynamicSymbolTable *table,
22
- char *symbolName) {
23
- DynamicSymbolList *symbol = (DynamicSymbolList *)calloc(sizeof(DynamicSymbolList), 1);
24
-
25
- symbol->symbol.string = stringTableAdd(table->stringTable, symbolName);
26
-
27
- symbol->next = table->symbols;
28
- table->symbols = symbol;
29
- table->count += 1;
30
-
31
- return &(symbol->symbol);
32
- }
33
-
34
- void dynamicSymbolTableFree(DynamicSymbolTable *table) {
35
- DynamicSymbolList *node=NULL, *next=NULL;
36
- for(node=table->symbols; node!=NULL; node=next) {
37
- next=node->next;
38
- free(node);
39
- }
40
- free(table);
41
- }
@@ -1,34 +0,0 @@
1
- #ifndef _DYNAMIC_SYMBOLS_
2
- #define _DYNAMIC_SYMBOLS_
3
-
4
- #include "string-table.h"
5
- #include <libelf.h>
6
-
7
- typedef struct {
8
- StringTableNode *string;
9
- Elf64_Sym *symbol;
10
- } DynamicSymbol;
11
-
12
- typedef struct DynamicSymbolList_ {
13
- DynamicSymbol symbol;
14
- struct DynamicSymbolList_ *next;
15
- } DynamicSymbolList;
16
-
17
- typedef struct {
18
- StringTable *stringTable;
19
-
20
- DynamicSymbol bssStart;
21
- DynamicSymbol eData;
22
- DynamicSymbol end;
23
-
24
- size_t count;
25
- DynamicSymbolList *symbols;
26
- } DynamicSymbolTable;
27
-
28
- DynamicSymbolTable *dynamicSymbolTableInit(StringTable *dynamicString);
29
- DynamicSymbol *dynamicSymbolTableAdd(DynamicSymbolTable *table,
30
- char *symbolName);
31
-
32
- void dynamicSymbolTableFree(DynamicSymbolTable *table);
33
-
34
- #endif
@@ -1,30 +0,0 @@
1
-
2
- #include <stdarg.h>
3
- #define _GNU_SOURCE
4
- #include <stdlib.h>
5
- #include <stdio.h>
6
-
7
- #include "errors.h"
8
-
9
- const char *sdtErrors[] = {
10
- "failed to create Elf shared library for provider '%s'",
11
- "failed to create temporary file '%s'",
12
- "failed to open shared library '%s': %s",
13
- "failed to load symbol '%s' for shared library '%s': %s",
14
- "failed to close shared library '%s' for provider '%s': %s",
15
- };
16
-
17
- void sdtSetError(SDTProvider_t *provider, SDTError_t error, ...) {
18
- va_list argp;
19
-
20
- if(provider->error != NULL) {
21
- free(provider->error);
22
- provider->error = NULL;
23
- provider->errno = noError;
24
- }
25
-
26
- va_start(argp, error);
27
- provider->errno = error;
28
- (void)vasprintf(&provider->error, sdtErrors[error], argp);
29
- va_end(argp);
30
- }
@@ -1,8 +0,0 @@
1
- #ifndef _ERRORS_H
2
- #define _ERRORS_H
3
-
4
- #include "libstapsdt.h"
5
-
6
- void sdtSetError(SDTProvider_t *provider, SDTError_t error, ...);
7
-
8
- #endif
@@ -1,27 +0,0 @@
1
- #include <stdio.h>
2
- #include "dynamic-symbols.h"
3
-
4
- size_t hashTableFromSymbolTable(DynamicSymbolTable *table, uint32_t **hashTable) {
5
- DynamicSymbolList *current;
6
- uint32_t nBuckets = table->count + 3, // + 3, to count bss, end, and eData symbols
7
- nChains = table->count + 3;
8
- size_t hashTableSize = (nBuckets + nChains + 2);
9
-
10
- uint32_t *hashTable_ = (uint32_t *)calloc(sizeof(uint32_t), hashTableSize);
11
- uint32_t *buckets = &(hashTable_[2]);
12
- uint32_t *chains = &(buckets[nBuckets]);
13
- int idx, stringIdx=2;
14
-
15
- hashTable_[0] = nBuckets;
16
- hashTable_[1] = nChains;
17
-
18
- for(current=table->symbols; current!=NULL; current=current->next) {
19
- idx = elf_hash(current->symbol.string->str) % nBuckets;
20
- chains[stringIdx] = buckets[idx];
21
- buckets[idx] = stringIdx;
22
- stringIdx++;
23
- }
24
-
25
- *hashTable = hashTable_;
26
- return hashTableSize * sizeof(uint32_t);
27
- }
@@ -1,3 +0,0 @@
1
- #include "dynamic-symbols.h"
2
-
3
- size_t hashTableFromSymbolTable(DynamicSymbolTable *table, uint32_t **hashTable);
@@ -1,208 +0,0 @@
1
- #include <stdarg.h>
2
- #include <dlfcn.h>
3
- #include <err.h>
4
- #include <fcntl.h>
5
- #include <libelf.h>
6
- #include <stdio.h>
7
- #include <stdlib.h>
8
- #include <string.h>
9
- #include <sys/types.h>
10
- #include <unistd.h>
11
-
12
- #include "dynamic-symbols.h"
13
- #include "sdtnote.h"
14
- #include "section.h"
15
- #include "string-table.h"
16
- #include "shared-lib.h"
17
- #include "util.h"
18
- #include "libstapsdt.h"
19
- #include "errors.h"
20
-
21
- int createSharedLibrary(int fd, SDTProvider_t *provider) {
22
- DynElf *dynElf = dynElfInit(fd);
23
-
24
- for(SDTProbeList_t *node=provider->probes; node != NULL; node = node->next) {
25
- dynElfAddProbe(dynElf, &(node->probe));
26
- }
27
-
28
- if(dynElfSave(dynElf) == -1) {
29
- sdtSetError(provider, elfCreationError, provider->name);
30
- return -1;
31
- }
32
-
33
- dynElfClose(dynElf);
34
-
35
- return 0;
36
- }
37
-
38
- SDTProvider_t *providerInit(const char *name) {
39
- SDTProvider_t *provider = (SDTProvider_t *) calloc(sizeof(SDTProvider_t), 1);
40
- provider->error = NULL;
41
- provider->errno = noError;
42
- provider->probes = NULL;
43
- provider->_handle = NULL;
44
- provider->_filename = NULL;
45
-
46
- provider->name = (char *) calloc(sizeof(char), strlen(name) + 1);
47
- memcpy(provider->name, name, sizeof(char) * strlen(name) + 1);
48
-
49
- return provider;
50
- }
51
-
52
- SDTProbe_t *providerAddProbe(SDTProvider_t *provider, const char *name, int argCount, ...) {
53
- int i;
54
- va_list vl;
55
- ArgType_t arg;
56
- va_start(vl, argCount);
57
-
58
- SDTProbeList_t *probeList = (SDTProbeList_t *) calloc(sizeof(SDTProbeList_t), 1);
59
- probeList->probe._fire = NULL;
60
-
61
- probeList->probe.name = (char *) calloc(sizeof(char), strlen(name) + 1);
62
- memcpy(probeList->probe.name, name, sizeof(char) * strlen(name) + 1);
63
-
64
- probeList->next = provider->probes;
65
- provider->probes = probeList;
66
-
67
- probeList->probe.argCount = argCount;
68
-
69
- for(i=0; i < argCount; i++) {
70
- arg = va_arg(vl, ArgType_t);
71
- probeList->probe.argFmt[i] = arg;
72
- }
73
-
74
- for(; i<MAX_ARGUMENTS; i++) {
75
- probeList->probe.argFmt[i] = noarg;
76
- }
77
-
78
- probeList->probe.provider = provider;
79
-
80
- return &(probeList->probe);
81
- }
82
-
83
- int providerLoad(SDTProvider_t *provider) {
84
- int fd;
85
- void *fireProbe;
86
- char *filename = calloc(sizeof(char), strlen("/tmp/-XXXXXX.so") + strlen(provider->name) + 1);
87
- char *error;
88
-
89
- sprintf(filename, "/tmp/%s-XXXXXX.so", provider->name);
90
-
91
- if ((fd = mkstemps(filename, 3)) < 0) {
92
- sdtSetError(provider, tmpCreationError, filename);
93
- free(filename);
94
- return -1;
95
- }
96
- provider->_filename = filename;
97
-
98
- if(createSharedLibrary(fd, provider) != 0) {
99
- (void)close(fd);
100
- return -1;
101
- }
102
- (void)close(fd);
103
-
104
- provider->_handle = dlopen(filename, RTLD_LAZY);
105
- if (!provider->_handle) {
106
- sdtSetError(provider, sharedLibraryOpenError, filename, dlerror());
107
- return -1;
108
- }
109
-
110
- for(SDTProbeList_t *node=provider->probes; node != NULL; node = node->next) {
111
- fireProbe = dlsym(provider->_handle, node->probe.name);
112
-
113
- // TODO (mmarchini) handle errors better when a symbol fails to load
114
- if ((error = dlerror()) != NULL) {
115
- sdtSetError(provider, sharedLibraryOpenError, filename, node->probe.name, error);
116
- return -1;
117
- }
118
-
119
- node->probe._fire = fireProbe;
120
- }
121
-
122
-
123
- return 0;
124
- }
125
-
126
- int providerUnload(SDTProvider_t *provider) {
127
- if(provider->_handle == NULL) {
128
- return 0;
129
- }
130
- if(dlclose(provider->_handle) != 0) {
131
- sdtSetError(provider, sharedLibraryCloseError, provider->_filename, provider->name, dlerror());
132
- return -1;
133
- }
134
- provider->_handle = NULL;
135
-
136
- for(SDTProbeList_t *node=provider->probes; node != NULL; node = node->next) {
137
- node->probe._fire = NULL;
138
- }
139
-
140
- unlink(provider->_filename);
141
- free(provider->_filename);
142
-
143
- return 0;
144
- }
145
-
146
- void probeFire(SDTProbe_t *probe, ...) {
147
- if(probe->_fire == NULL) {
148
- return;
149
- }
150
- va_list vl;
151
- va_start(vl, probe);
152
- uint64_t arg[6] = {0};
153
- for(int i=0; i < probe->argCount; i++) {
154
- arg[i] = va_arg(vl, uint64_t);
155
- }
156
-
157
- switch(probe->argCount) {
158
- case 0:
159
- ((void (*)())probe->_fire) ();
160
- return;
161
- case 1:
162
- ((void (*)())probe->_fire) (arg[0]);
163
- return;
164
- case 2:
165
- ((void (*)())probe->_fire) (arg[0], arg[1]);
166
- return;
167
- case 3:
168
- ((void (*)())probe->_fire) (arg[0], arg[1], arg[2]);
169
- return;
170
- case 4:
171
- ((void (*)())probe->_fire) (arg[0], arg[1], arg[2], arg[3]);
172
- return;
173
- case 5:
174
- ((void (*)())probe->_fire) (arg[0], arg[1], arg[2], arg[3], arg[4]);
175
- return;
176
- case 6:
177
- ((void (*)())probe->_fire) (arg[0], arg[1], arg[2], arg[3], arg[4], arg[5]);
178
- return;
179
- default:
180
- ((void (*)())probe->_fire) ();
181
- return;
182
- }
183
- }
184
-
185
- int probeIsEnabled(SDTProbe_t *probe) {
186
- if(probe->_fire == NULL) {
187
- return 0;
188
- }
189
- if(((*(char *)probe->_fire) & 0x90) == 0x90) {
190
- return 0;
191
- }
192
- return 1;
193
- }
194
-
195
- void providerDestroy(SDTProvider_t *provider) {
196
- SDTProbeList_t *node=NULL, *next=NULL;
197
-
198
- for(node=provider->probes; node!=NULL; node=next) {
199
- free(node->probe.name);
200
- next=node->next;
201
- free(node);
202
- }
203
- free(provider->name);
204
- if(provider->error != NULL) {
205
- free(provider->error);
206
- }
207
- free(provider);
208
- }