Commit 9509d91
[Tracing] Instrument static methods defined in non-generic value types (#7920)
## Summary of changes
Adds the capability to instrument static methods defined in non-generic
value types
## Reason for change
We will need to instrument OpenTelemetry Baggage, which utilizes static
methods in a Baggage struct
## Implementation details
- When instrumenting a method for CallTarget instrumentation, optionally
update the LocalVarSig with a local variable of the owning type if the
following conditions are met:
1. The method is static
2. The owning type of the method is a value type
- Update `TracerMethodRewriter::Rewrite` such that when it is loading
the object instance to put on the stack for a static method, for
non-generic value types it does the following:
- `ldloca.s [localIndex]` (Loads the variable addresses)
- `initobj [valueType]` (Initializes, or re-initializes, an empty
struct)
- `ldloc.s [localIndex]` (Loads the struct onto the stack)
## Test coverage
The `CallTargetNativeTest` is updated with the following cases to
demonstrate the new functionality, especially as it compares to
reference types:
- New `ArgumentsGenericStatic` types demonstrate the successful
instrumentation of static methods in _generic_ reference types
- New `ArgumentsStaticStruct` types demonstrate the successful
instrumentation of static methods in value types
- New `ArgumentsGenericStaticStruct` types demonstrate the unsuccessful
instrumentation of static methods in _generic_ value types
## Other details
Note: This does not implement the functionality for the live debugger IL
rewriting, though it does update the method call so that everything
compiles.
---------
Co-authored-by: Andrew Lock <andrew.lock@datadoghq.com>1 parent 13ff155 commit 9509d91
16 files changed
Lines changed: 3114 additions & 50 deletions
File tree
- tracer
- src/Datadog.Tracer.Native
- test
- Datadog.Trace.ClrProfiler.IntegrationTests
- test-applications/instrumentation/CallTargetNativeTest
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
358 | 358 | | |
359 | 359 | | |
360 | 360 | | |
361 | | - | |
| 361 | + | |
362 | 362 | | |
363 | | - | |
| 363 | + | |
364 | 364 | | |
365 | 365 | | |
366 | 366 | | |
| |||
399 | 399 | | |
400 | 400 | | |
401 | 401 | | |
402 | | - | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
403 | 413 | | |
404 | 414 | | |
405 | 415 | | |
| |||
496 | 506 | | |
497 | 507 | | |
498 | 508 | | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
499 | 516 | | |
500 | 517 | | |
501 | 518 | | |
| |||
519 | 536 | | |
520 | 537 | | |
521 | 538 | | |
522 | | - | |
| 539 | + | |
523 | 540 | | |
524 | 541 | | |
525 | 542 | | |
| |||
533 | 550 | | |
534 | 551 | | |
535 | 552 | | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
536 | 562 | | |
537 | 563 | | |
538 | 564 | | |
| |||
870 | 896 | | |
871 | 897 | | |
872 | 898 | | |
873 | | - | |
| 899 | + | |
874 | 900 | | |
875 | | - | |
| 901 | + | |
876 | 902 | | |
877 | 903 | | |
878 | 904 | | |
| |||
881 | 907 | | |
882 | 908 | | |
883 | 909 | | |
884 | | - | |
885 | | - | |
| 910 | + | |
| 911 | + | |
886 | 912 | | |
887 | 913 | | |
888 | 914 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
50 | | - | |
| 49 | + | |
| 50 | + | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
101 | | - | |
| 100 | + | |
| 101 | + | |
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| |||
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2239 | 2239 | | |
2240 | 2240 | | |
2241 | 2241 | | |
| 2242 | + | |
2242 | 2243 | | |
2243 | 2244 | | |
2244 | 2245 | | |
| |||
2275 | 2276 | | |
2276 | 2277 | | |
2277 | 2278 | | |
2278 | | - | |
2279 | | - | |
| 2279 | + | |
| 2280 | + | |
2280 | 2281 | | |
2281 | 2282 | | |
2282 | 2283 | | |
| |||
Lines changed: 68 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
75 | | - | |
76 | | - | |
| 74 | + | |
| 75 | + | |
77 | 76 | | |
78 | | - | |
| 77 | + | |
79 | 78 | | |
80 | | - | |
| 79 | + | |
81 | 80 | | |
82 | 81 | | |
83 | 82 | | |
| |||
183 | 182 | | |
184 | 183 | | |
185 | 184 | | |
| 185 | + | |
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
| |||
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
196 | | - | |
| 196 | + | |
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
| |||
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
210 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
211 | 240 | | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
| 241 | + | |
221 | 242 | | |
222 | | - | |
223 | 243 | | |
224 | 244 | | |
225 | 245 | | |
| |||
505 | 525 | | |
506 | 526 | | |
507 | 527 | | |
508 | | - | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
509 | 558 | | |
510 | | - | |
511 | | - | |
512 | | - | |
513 | | - | |
514 | | - | |
515 | | - | |
516 | | - | |
517 | | - | |
518 | | - | |
519 | | - | |
520 | | - | |
| 559 | + | |
521 | 560 | | |
522 | | - | |
523 | 561 | | |
524 | 562 | | |
525 | 563 | | |
| |||
Lines changed: 6 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
69 | | - | |
| 68 | + | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
75 | | - | |
| 74 | + | |
| 75 | + | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
81 | | - | |
| 80 | + | |
| 81 | + | |
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| |||
0 commit comments