pf2 0.6.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -0
  3. data/Cargo.lock +6 -26
  4. data/crates/backtrace-sys2/build.rs +1 -4
  5. data/crates/backtrace-sys2/src/libbacktrace/Makefile.am +116 -31
  6. data/crates/backtrace-sys2/src/libbacktrace/Makefile.in +295 -141
  7. data/crates/backtrace-sys2/src/libbacktrace/README.md +11 -1
  8. data/crates/backtrace-sys2/src/libbacktrace/alloc.c +1 -1
  9. data/crates/backtrace-sys2/src/libbacktrace/allocfail.c +1 -1
  10. data/crates/backtrace-sys2/src/libbacktrace/allocfail.sh +1 -1
  11. data/crates/backtrace-sys2/src/libbacktrace/atomic.c +1 -1
  12. data/crates/backtrace-sys2/src/libbacktrace/backtrace-supported.h.in +1 -1
  13. data/crates/backtrace-sys2/src/libbacktrace/backtrace.c +1 -1
  14. data/crates/backtrace-sys2/src/libbacktrace/backtrace.h +12 -12
  15. data/crates/backtrace-sys2/src/libbacktrace/btest.c +24 -8
  16. data/crates/backtrace-sys2/src/libbacktrace/config/libtool.m4 +162 -53
  17. data/crates/backtrace-sys2/src/libbacktrace/config.h.in +3 -0
  18. data/crates/backtrace-sys2/src/libbacktrace/configure +255 -66
  19. data/crates/backtrace-sys2/src/libbacktrace/configure.ac +27 -8
  20. data/crates/backtrace-sys2/src/libbacktrace/dwarf.c +37 -30
  21. data/crates/backtrace-sys2/src/libbacktrace/edtest.c +2 -2
  22. data/crates/backtrace-sys2/src/libbacktrace/edtest2.c +1 -1
  23. data/crates/backtrace-sys2/src/libbacktrace/elf.c +98 -76
  24. data/crates/backtrace-sys2/src/libbacktrace/fileline.c +1 -1
  25. data/crates/backtrace-sys2/src/libbacktrace/install-debuginfo-for-buildid.sh.in +2 -2
  26. data/crates/backtrace-sys2/src/libbacktrace/instrumented_alloc.c +1 -1
  27. data/crates/backtrace-sys2/src/libbacktrace/internal.h +41 -2
  28. data/crates/backtrace-sys2/src/libbacktrace/macho.c +25 -19
  29. data/crates/backtrace-sys2/src/libbacktrace/mmap.c +1 -1
  30. data/crates/backtrace-sys2/src/libbacktrace/mmapio.c +1 -1
  31. data/crates/backtrace-sys2/src/libbacktrace/mtest.c +4 -4
  32. data/crates/backtrace-sys2/src/libbacktrace/nounwind.c +1 -1
  33. data/crates/backtrace-sys2/src/libbacktrace/pecoff.c +192 -26
  34. data/crates/backtrace-sys2/src/libbacktrace/posix.c +1 -1
  35. data/crates/backtrace-sys2/src/libbacktrace/print.c +41 -16
  36. data/crates/backtrace-sys2/src/libbacktrace/read.c +1 -1
  37. data/crates/backtrace-sys2/src/libbacktrace/simple.c +1 -1
  38. data/crates/backtrace-sys2/src/libbacktrace/sort.c +1 -1
  39. data/crates/backtrace-sys2/src/libbacktrace/state.c +1 -1
  40. data/crates/backtrace-sys2/src/libbacktrace/stest.c +1 -1
  41. data/crates/backtrace-sys2/src/libbacktrace/test_format.c +1 -1
  42. data/crates/backtrace-sys2/src/libbacktrace/testlib.c +1 -1
  43. data/crates/backtrace-sys2/src/libbacktrace/testlib.h +1 -1
  44. data/crates/backtrace-sys2/src/libbacktrace/ttest.c +1 -1
  45. data/crates/backtrace-sys2/src/libbacktrace/unittest.c +1 -1
  46. data/crates/backtrace-sys2/src/libbacktrace/unknown.c +1 -1
  47. data/crates/backtrace-sys2/src/libbacktrace/xcoff.c +43 -32
  48. data/crates/backtrace-sys2/src/libbacktrace/xztest.c +2 -2
  49. data/crates/backtrace-sys2/src/libbacktrace/zstdtest.c +1 -1
  50. data/crates/backtrace-sys2/src/libbacktrace/ztest.c +1 -1
  51. data/ext/pf2/Cargo.toml +1 -1
  52. data/ext/pf2/src/profile_serializer.rs +5 -12
  53. data/ext/pf2/src/ringbuffer.rs +1 -3
  54. data/ext/pf2/src/ruby_init.rs +1 -4
  55. data/ext/pf2/src/sample.rs +1 -0
  56. data/ext/pf2/src/serialization/profile.rs +2 -1
  57. data/ext/pf2/src/serialization/serializer.rs +227 -48
  58. data/ext/pf2/src/session/new_thread_watcher.rs +1 -1
  59. data/ext/pf2/src/session/ruby_object.rs +1 -5
  60. data/ext/pf2/src/session.rs +5 -15
  61. data/ext/pf2/src/signal_scheduler.rs +9 -10
  62. data/ext/pf2/src/timer_thread_scheduler.rs +8 -6
  63. data/lib/pf2/cli.rb +2 -0
  64. data/lib/pf2/reporter/firefox_profiler.rb +2 -0
  65. data/lib/pf2/reporter/stack_weaver.rb +81 -0
  66. data/lib/pf2/reporter.rb +3 -4
  67. data/lib/pf2/serve.rb +2 -0
  68. data/lib/pf2/session.rb +2 -0
  69. data/lib/pf2/version.rb +3 -1
  70. data/lib/pf2.rb +4 -1
  71. data/rust-toolchain.toml +2 -0
  72. data/rustfmt.toml +1 -0
  73. metadata +10 -12
  74. data/crates/backtrace-sys2/src/libbacktrace/libtool.m4 +0 -7436
  75. data/crates/backtrace-sys2/src/libbacktrace/ltoptions.m4 +0 -369
  76. data/crates/backtrace-sys2/src/libbacktrace/ltsugar.m4 +0 -123
  77. data/crates/backtrace-sys2/src/libbacktrace/ltversion.m4 +0 -23
  78. data/crates/backtrace-sys2/src/libbacktrace/lt~obsolete.m4 +0 -98
@@ -1,5 +1,5 @@
1
1
  /* internal.h -- Internal header file for stack backtrace library.
2
- Copyright (C) 2012-2021 Free Software Foundation, Inc.
2
+ Copyright (C) 2012-2024 Free Software Foundation, Inc.
3
3
  Written by Ian Lance Taylor, Google.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
@@ -56,6 +56,11 @@ POSSIBILITY OF SUCH DAMAGE. */
56
56
  # endif
57
57
  #endif
58
58
 
59
+ #ifdef __has_attribute
60
+ # if __has_attribute(fallthrough)
61
+ # define ATTRIBUTE_FALLTHROUGH __attribute__ ((fallthrough))
62
+ # endif
63
+ #endif
59
64
  #ifndef ATTRIBUTE_FALLTHROUGH
60
65
  # if (GCC_VERSION >= 7000)
61
66
  # define ATTRIBUTE_FALLTHROUGH __attribute__ ((__fallthrough__))
@@ -323,10 +328,44 @@ struct dwarf_sections
323
328
 
324
329
  struct dwarf_data;
325
330
 
331
+ /* The load address mapping. */
332
+
333
+ #if defined(__FDPIC__) && defined(HAVE_DL_ITERATE_PHDR) && (defined(HAVE_LINK_H) || defined(HAVE_SYS_LINK_H))
334
+
335
+ #ifdef HAVE_LINK_H
336
+ #include <link.h>
337
+ #endif
338
+ #ifdef HAVE_SYS_LINK_H
339
+ #include <sys/link.h>
340
+ #endif
341
+
342
+ #define libbacktrace_using_fdpic() (1)
343
+
344
+ struct libbacktrace_base_address
345
+ {
346
+ struct elf32_fdpic_loadaddr m;
347
+ };
348
+
349
+ #define libbacktrace_add_base(pc, base) \
350
+ ((uintptr_t) (__RELOC_POINTER ((pc), (base).m)))
351
+
352
+ #else /* not _FDPIC__ */
353
+
354
+ #define libbacktrace_using_fdpic() (0)
355
+
356
+ struct libbacktrace_base_address
357
+ {
358
+ uintptr_t m;
359
+ };
360
+
361
+ #define libbacktrace_add_base(pc, base) ((pc) + (base).m)
362
+
363
+ #endif /* not _FDPIC__ */
364
+
326
365
  /* Add file/line information for a DWARF module. */
327
366
 
328
367
  extern int backtrace_dwarf_add (struct backtrace_state *state,
329
- uintptr_t base_address,
368
+ struct libbacktrace_base_address base_address,
330
369
  const struct dwarf_sections *dwarf_sections,
331
370
  int is_bigendian,
332
371
  struct dwarf_data *fileline_altlink,
@@ -1,5 +1,5 @@
1
1
  /* elf.c -- Get debug data from a Mach-O file for backtraces.
2
- Copyright (C) 2020-2021 Free Software Foundation, Inc.
2
+ Copyright (C) 2020-2024 Free Software Foundation, Inc.
3
3
  Written by Ian Lance Taylor, Google.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
@@ -271,12 +271,14 @@ struct macho_nlist_64
271
271
 
272
272
  /* Value found in nlist n_type field. */
273
273
 
274
- #define MACH_O_N_EXT 0x01 /* Extern symbol */
274
+ #define MACH_O_N_STAB 0xe0 /* Stabs debugging symbol */
275
+ #define MACH_O_N_TYPE 0x0e /* Mask for type bits */
276
+
277
+ /* Values found after masking with MACH_O_N_TYPE. */
278
+ #define MACH_O_N_UNDF 0x00 /* Undefined symbol */
275
279
  #define MACH_O_N_ABS 0x02 /* Absolute symbol */
276
- #define MACH_O_N_SECT 0x0e /* Defined in section */
280
+ #define MACH_O_N_SECT 0x0e /* Defined in section from n_sect field */
277
281
 
278
- #define MACH_O_N_TYPE 0x0e /* Mask for type bits */
279
- #define MACH_O_N_STAB 0xe0 /* Stabs debugging symbol */
280
282
 
281
283
  /* Information we keep for a Mach-O symbol. */
282
284
 
@@ -313,8 +315,9 @@ static const char * const dwarf_section_names[DEBUG_MAX] =
313
315
  /* Forward declaration. */
314
316
 
315
317
  static int macho_add (struct backtrace_state *, const char *, int, off_t,
316
- const unsigned char *, uintptr_t, int,
317
- backtrace_error_callback, void *, fileline *, int *);
318
+ const unsigned char *, struct libbacktrace_base_address,
319
+ int, backtrace_error_callback, void *, fileline *,
320
+ int *);
318
321
 
319
322
  /* A dummy callback function used when we can't find any debug info. */
320
323
 
@@ -324,7 +327,7 @@ macho_nodebug (struct backtrace_state *state ATTRIBUTE_UNUSED,
324
327
  backtrace_full_callback callback ATTRIBUTE_UNUSED,
325
328
  backtrace_error_callback error_callback, void *data)
326
329
  {
327
- error_callback (data, "no debug info in Mach-O executable", -1);
330
+ error_callback (data, "no debug info in Mach-O executable (make sure to compile with -g; may need to run dsymutil)", -1);
328
331
  return 0;
329
332
  }
330
333
 
@@ -492,10 +495,10 @@ macho_defined_symbol (uint8_t type)
492
495
  {
493
496
  if ((type & MACH_O_N_STAB) != 0)
494
497
  return 0;
495
- if ((type & MACH_O_N_EXT) != 0)
496
- return 0;
497
498
  switch (type & MACH_O_N_TYPE)
498
499
  {
500
+ case MACH_O_N_UNDF:
501
+ return 0;
499
502
  case MACH_O_N_ABS:
500
503
  return 1;
501
504
  case MACH_O_N_SECT:
@@ -509,7 +512,7 @@ macho_defined_symbol (uint8_t type)
509
512
 
510
513
  static int
511
514
  macho_add_symtab (struct backtrace_state *state, int descriptor,
512
- uintptr_t base_address, int is_64,
515
+ struct libbacktrace_base_address base_address, int is_64,
513
516
  off_t symoff, unsigned int nsyms, off_t stroff,
514
517
  unsigned int strsize,
515
518
  backtrace_error_callback error_callback, void *data)
@@ -624,7 +627,7 @@ macho_add_symtab (struct backtrace_state *state, int descriptor,
624
627
  if (name[0] == '_')
625
628
  ++name;
626
629
  macho_symbols[j].name = name;
627
- macho_symbols[j].address = value + base_address;
630
+ macho_symbols[j].address = libbacktrace_add_base (value, base_address);
628
631
  ++j;
629
632
  }
630
633
 
@@ -674,7 +677,6 @@ macho_add_symtab (struct backtrace_state *state, int descriptor,
674
677
  struct macho_syminfo_data *p;
675
678
 
676
679
  p = backtrace_atomic_load_pointer (pp);
677
-
678
680
  if (p == NULL)
679
681
  break;
680
682
 
@@ -757,7 +759,8 @@ macho_syminfo (struct backtrace_state *state, uintptr_t addr,
757
759
  static int
758
760
  macho_add_fat (struct backtrace_state *state, const char *filename,
759
761
  int descriptor, int swapped, off_t offset,
760
- const unsigned char *match_uuid, uintptr_t base_address,
762
+ const unsigned char *match_uuid,
763
+ struct libbacktrace_base_address base_address,
761
764
  int skip_symtab, uint32_t nfat_arch, int is_64,
762
765
  backtrace_error_callback error_callback, void *data,
763
766
  fileline *fileline_fn, int *found_sym)
@@ -859,7 +862,8 @@ macho_add_fat (struct backtrace_state *state, const char *filename,
859
862
 
860
863
  static int
861
864
  macho_add_dsym (struct backtrace_state *state, const char *filename,
862
- uintptr_t base_address, const unsigned char *uuid,
865
+ struct libbacktrace_base_address base_address,
866
+ const unsigned char *uuid,
863
867
  backtrace_error_callback error_callback, void *data,
864
868
  fileline* fileline_fn)
865
869
  {
@@ -977,7 +981,7 @@ macho_add_dsym (struct backtrace_state *state, const char *filename,
977
981
  static int
978
982
  macho_add (struct backtrace_state *state, const char *filename, int descriptor,
979
983
  off_t offset, const unsigned char *match_uuid,
980
- uintptr_t base_address, int skip_symtab,
984
+ struct libbacktrace_base_address base_address, int skip_symtab,
981
985
  backtrace_error_callback error_callback, void *data,
982
986
  fileline *fileline_fn, int *found_sym)
983
987
  {
@@ -1239,7 +1243,7 @@ backtrace_initialize (struct backtrace_state *state, const char *filename,
1239
1243
  c = _dyld_image_count ();
1240
1244
  for (i = 0; i < c; ++i)
1241
1245
  {
1242
- uintptr_t base_address;
1246
+ struct libbacktrace_base_address base_address;
1243
1247
  const char *name;
1244
1248
  int d;
1245
1249
  fileline mff;
@@ -1263,7 +1267,7 @@ backtrace_initialize (struct backtrace_state *state, const char *filename,
1263
1267
  continue;
1264
1268
  }
1265
1269
 
1266
- base_address = _dyld_get_image_vmaddr_slide (i);
1270
+ base_address.m = _dyld_get_image_vmaddr_slide (i);
1267
1271
 
1268
1272
  mff = macho_nodebug;
1269
1273
  if (!macho_add (state, name, d, 0, NULL, base_address, 0,
@@ -1318,10 +1322,12 @@ backtrace_initialize (struct backtrace_state *state, const char *filename,
1318
1322
  void *data, fileline *fileline_fn)
1319
1323
  {
1320
1324
  fileline macho_fileline_fn;
1325
+ struct libbacktrace_base_address zero_base_address;
1321
1326
  int found_sym;
1322
1327
 
1323
1328
  macho_fileline_fn = macho_nodebug;
1324
- if (!macho_add (state, filename, descriptor, 0, NULL, 0, 0,
1329
+ memset (&zero_base_address, 0, sizeof zero_base_address);
1330
+ if (!macho_add (state, filename, descriptor, 0, NULL, zero_base_address, 0,
1325
1331
  error_callback, data, &macho_fileline_fn, &found_sym))
1326
1332
  return 0;
1327
1333
 
@@ -1,5 +1,5 @@
1
1
  /* mmap.c -- Memory allocation with mmap.
2
- Copyright (C) 2012-2021 Free Software Foundation, Inc.
2
+ Copyright (C) 2012-2024 Free Software Foundation, Inc.
3
3
  Written by Ian Lance Taylor, Google.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  /* mmapio.c -- File views using mmap.
2
- Copyright (C) 2012-2021 Free Software Foundation, Inc.
2
+ Copyright (C) 2012-2024 Free Software Foundation, Inc.
3
3
  Written by Ian Lance Taylor, Google.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  /* mtest.c -- Minidebug test for libbacktrace library
2
- Copyright (C) 2020-2021 Free Software Foundation, Inc.
2
+ Copyright (C) 2020-2024 Free Software Foundation, Inc.
3
3
  Written by Ian Lance Taylor, Google.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
@@ -47,7 +47,7 @@ POSSIBILITY OF SUCH DAMAGE. */
47
47
 
48
48
  #include "testlib.h"
49
49
 
50
- static int test1 (void) __attribute__ ((noinline, noclone, unused));
50
+ static int test1 (void) __attribute__ ((noinline, noclone, optnone, unused));
51
51
  static int f2 (int) __attribute__ ((noinline, noclone));
52
52
  static int f3 (int, int) __attribute__ ((noinline, noclone));
53
53
 
@@ -211,7 +211,7 @@ f3 (int f1line __attribute__ ((unused)), int f2line __attribute__ ((unused)))
211
211
 
212
212
  /* Test the backtrace_simple function with non-inlined functions. */
213
213
 
214
- static int test3 (void) __attribute__ ((noinline, noclone, unused));
214
+ static int test3 (void) __attribute__ ((noinline, noclone, optnone, unused));
215
215
  static int f22 (int) __attribute__ ((noinline, noclone));
216
216
  static int f23 (int, int) __attribute__ ((noinline, noclone));
217
217
 
@@ -373,7 +373,7 @@ test5 (void)
373
373
  (unsigned long) (uintptr_t) &global);
374
374
  symdata.failed = 1;
375
375
  }
376
- else if (symdata.size != sizeof (global))
376
+ else if (symdata.size != sizeof (global) && symdata.size != 0)
377
377
  {
378
378
  fprintf (stderr,
379
379
  "test5: unexpected syminfo size got %lx expected %lx\n",
@@ -1,5 +1,5 @@
1
1
  /* backtrace.c -- Entry point for stack backtrace library.
2
- Copyright (C) 2012-2021 Free Software Foundation, Inc.
2
+ Copyright (C) 2012-2024 Free Software Foundation, Inc.
3
3
  Written by Ian Lance Taylor, Google.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  /* pecoff.c -- Get debug data from a PE/COFFF file for backtraces.
2
- Copyright (C) 2015-2021 Free Software Foundation, Inc.
2
+ Copyright (C) 2015-2024 Free Software Foundation, Inc.
3
3
  Adapted from elf.c by Tristan Gingold, AdaCore.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
@@ -49,6 +49,46 @@ POSSIBILITY OF SUCH DAMAGE. */
49
49
  #endif
50
50
 
51
51
  #include <windows.h>
52
+
53
+ #ifdef HAVE_TLHELP32_H
54
+ #include <tlhelp32.h>
55
+
56
+ #ifdef UNICODE
57
+ /* If UNICODE is defined, all the symbols are replaced by a macro to use the
58
+ wide variant. But we need the ansi variant, so undef the macros. */
59
+ #undef MODULEENTRY32
60
+ #undef Module32First
61
+ #undef Module32Next
62
+ #endif
63
+ #endif
64
+
65
+ #if defined(_ARM_)
66
+ #define NTAPI
67
+ #else
68
+ #define NTAPI __stdcall
69
+ #endif
70
+
71
+ /* This is a simplified (but binary compatible) version of what Microsoft
72
+ defines in their documentation. */
73
+ struct dll_notification_data
74
+ {
75
+ ULONG reserved;
76
+ /* The name as UNICODE_STRING struct. */
77
+ PVOID full_dll_name;
78
+ PVOID base_dll_name;
79
+ PVOID dll_base;
80
+ ULONG size_of_image;
81
+ };
82
+
83
+ #define LDR_DLL_NOTIFICATION_REASON_LOADED 1
84
+
85
+ typedef LONG NTSTATUS;
86
+ typedef VOID (CALLBACK *LDR_DLL_NOTIFICATION)(ULONG,
87
+ struct dll_notification_data*,
88
+ PVOID);
89
+ typedef NTSTATUS (NTAPI *LDR_REGISTER_FUNCTION)(ULONG,
90
+ LDR_DLL_NOTIFICATION, PVOID,
91
+ PVOID*);
52
92
  #endif
53
93
 
54
94
  /* Coff file header. */
@@ -200,7 +240,7 @@ coff_nodebug (struct backtrace_state *state ATTRIBUTE_UNUSED,
200
240
  backtrace_full_callback callback ATTRIBUTE_UNUSED,
201
241
  backtrace_error_callback error_callback, void *data)
202
242
  {
203
- error_callback (data, "no debug info in PE/COFF executable", -1);
243
+ error_callback (data, "no debug info in PE/COFF executable (make sure to compile with -g)", -1);
204
244
  return 0;
205
245
  }
206
246
 
@@ -342,10 +382,11 @@ coff_is_function_symbol (const b_coff_internal_symbol *isym)
342
382
 
343
383
  static int
344
384
  coff_initialize_syminfo (struct backtrace_state *state,
345
- uintptr_t base_address, int is_64,
346
- const b_coff_section_header *sects, size_t sects_num,
347
- const b_coff_external_symbol *syms, size_t syms_size,
348
- const unsigned char *strtab, size_t strtab_size,
385
+ struct libbacktrace_base_address base_address,
386
+ int is_64, const b_coff_section_header *sects,
387
+ size_t sects_num, const b_coff_external_symbol *syms,
388
+ size_t syms_size, const unsigned char *strtab,
389
+ size_t strtab_size,
349
390
  backtrace_error_callback error_callback,
350
391
  void *data, struct coff_syminfo_data *sdata)
351
392
  {
@@ -450,9 +491,10 @@ coff_initialize_syminfo (struct backtrace_state *state,
450
491
  secnum = coff_read2 (asym->section_number);
451
492
 
452
493
  coff_sym->name = name;
453
- coff_sym->address = (coff_read4 (asym->value)
454
- + sects[secnum - 1].virtual_address
455
- + base_address);
494
+ coff_sym->address =
495
+ libbacktrace_add_base ((coff_read4 (asym->value)
496
+ + sects[secnum - 1].virtual_address),
497
+ base_address);
456
498
  coff_sym++;
457
499
  }
458
500
 
@@ -592,7 +634,8 @@ coff_syminfo (struct backtrace_state *state, uintptr_t addr,
592
634
  static int
593
635
  coff_add (struct backtrace_state *state, int descriptor,
594
636
  backtrace_error_callback error_callback, void *data,
595
- fileline *fileline_fn, int *found_sym, int *found_dwarf)
637
+ fileline *fileline_fn, int *found_sym, int *found_dwarf,
638
+ uintptr_t module_handle ATTRIBUTE_UNUSED)
596
639
  {
597
640
  struct backtrace_view fhdr_view;
598
641
  off_t fhdr_off;
@@ -621,8 +664,8 @@ coff_add (struct backtrace_state *state, int descriptor,
621
664
  struct backtrace_view debug_view;
622
665
  int debug_view_valid;
623
666
  int is_64;
624
- uintptr_t image_base;
625
- uintptr_t base_address = 0;
667
+ struct libbacktrace_base_address image_base;
668
+ struct libbacktrace_base_address base_address;
626
669
  struct dwarf_sections dwarf_sections;
627
670
 
628
671
  *found_sym = 0;
@@ -661,7 +704,7 @@ coff_add (struct backtrace_state *state, int descriptor,
661
704
  magic_ok = memcmp (magic, "PE\0", 4) == 0;
662
705
  fhdr_off += 4;
663
706
 
664
- memcpy (&fhdr, fhdr_view.data + 4, sizeof fhdr);
707
+ memcpy (&fhdr, (const unsigned char *) fhdr_view.data + 4, sizeof fhdr);
665
708
  }
666
709
  else
667
710
  {
@@ -695,16 +738,17 @@ coff_add (struct backtrace_state *state, int descriptor,
695
738
  sects_view_valid = 1;
696
739
  opt_hdr = (const b_coff_optional_header *) sects_view.data;
697
740
  sects = (const b_coff_section_header *)
698
- (sects_view.data + fhdr.size_of_optional_header);
741
+ ((const unsigned char *) sects_view.data + fhdr.size_of_optional_header);
699
742
 
700
743
  is_64 = 0;
744
+ memset (&image_base, 0, sizeof image_base);
701
745
  if (fhdr.size_of_optional_header > sizeof (*opt_hdr))
702
746
  {
703
747
  if (opt_hdr->magic == PE_MAGIC)
704
- image_base = opt_hdr->u.pe.image_base;
748
+ image_base.m = opt_hdr->u.pe.image_base;
705
749
  else if (opt_hdr->magic == PEP_MAGIC)
706
750
  {
707
- image_base = opt_hdr->u.pep.image_base;
751
+ image_base.m = opt_hdr->u.pep.image_base;
708
752
  is_64 = 1;
709
753
  }
710
754
  else
@@ -713,8 +757,6 @@ coff_add (struct backtrace_state *state, int descriptor,
713
757
  goto fail;
714
758
  }
715
759
  }
716
- else
717
- image_base = 0;
718
760
 
719
761
  /* Read the symbol table and the string table. */
720
762
 
@@ -739,7 +781,8 @@ coff_add (struct backtrace_state *state, int descriptor,
739
781
  goto fail;
740
782
  syms_view_valid = 1;
741
783
 
742
- str_size = coff_read4 (syms_view.data + syms_size);
784
+ str_size = coff_read4 ((const unsigned char *) syms_view.data
785
+ + syms_size);
743
786
 
744
787
  str_off = syms_off + syms_size;
745
788
 
@@ -869,13 +912,9 @@ coff_add (struct backtrace_state *state, int descriptor,
869
912
  + (sections[i].offset - min_offset));
870
913
  }
871
914
 
915
+ memset (&base_address, 0, sizeof base_address);
872
916
  #ifdef HAVE_WINDOWS_H
873
- {
874
- uintptr_t module_handle;
875
-
876
- module_handle = (uintptr_t) GetModuleHandle (NULL);
877
- base_address = module_handle - image_base;
878
- }
917
+ base_address.m = module_handle - image_base.m;
879
918
  #endif
880
919
 
881
920
  if (!backtrace_dwarf_add (state, base_address, &dwarf_sections,
@@ -903,6 +942,53 @@ coff_add (struct backtrace_state *state, int descriptor,
903
942
  return 0;
904
943
  }
905
944
 
945
+ #ifdef HAVE_WINDOWS_H
946
+ struct dll_notification_context
947
+ {
948
+ struct backtrace_state *state;
949
+ backtrace_error_callback error_callback;
950
+ void *data;
951
+ };
952
+
953
+ static VOID CALLBACK
954
+ dll_notification (ULONG reason,
955
+ struct dll_notification_data *notification_data,
956
+ PVOID context)
957
+ {
958
+ char module_name[MAX_PATH];
959
+ int descriptor;
960
+ struct dll_notification_context* dll_context =
961
+ (struct dll_notification_context*) context;
962
+ struct backtrace_state *state = dll_context->state;
963
+ void *data = dll_context->data;
964
+ backtrace_error_callback error_callback = dll_context->data;
965
+ fileline fileline;
966
+ int found_sym;
967
+ int found_dwarf;
968
+ HMODULE module_handle;
969
+
970
+ if (reason != LDR_DLL_NOTIFICATION_REASON_LOADED)
971
+ return;
972
+
973
+ if (!GetModuleHandleExW ((GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
974
+ | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT),
975
+ (wchar_t*) notification_data->dll_base,
976
+ &module_handle))
977
+ return;
978
+
979
+ if (!GetModuleFileNameA ((HMODULE) module_handle, module_name, MAX_PATH - 1))
980
+ return;
981
+
982
+ descriptor = backtrace_open (module_name, error_callback, data, NULL);
983
+
984
+ if (descriptor < 0)
985
+ return;
986
+
987
+ coff_add (state, descriptor, error_callback, data, &fileline, &found_sym,
988
+ &found_dwarf, (uintptr_t) module_handle);
989
+ }
990
+ #endif /* defined(HAVE_WINDOWS_H) */
991
+
906
992
  /* Initialize the backtrace data we need from an ELF executable. At
907
993
  the ELF level, all we need to do is find the debug info
908
994
  sections. */
@@ -917,12 +1003,92 @@ backtrace_initialize (struct backtrace_state *state,
917
1003
  int found_sym;
918
1004
  int found_dwarf;
919
1005
  fileline coff_fileline_fn;
1006
+ uintptr_t module_handle = 0;
1007
+ #ifdef HAVE_TLHELP32_H
1008
+ fileline module_fileline_fn;
1009
+ int module_found_sym;
1010
+ HANDLE snapshot;
1011
+ #endif
1012
+
1013
+ #ifdef HAVE_WINDOWS_H
1014
+ HMODULE nt_dll_handle;
1015
+
1016
+ module_handle = (uintptr_t) GetModuleHandle (NULL);
1017
+ #endif
920
1018
 
921
1019
  ret = coff_add (state, descriptor, error_callback, data,
922
- &coff_fileline_fn, &found_sym, &found_dwarf);
1020
+ &coff_fileline_fn, &found_sym, &found_dwarf, module_handle);
923
1021
  if (!ret)
924
1022
  return 0;
925
1023
 
1024
+ #ifdef HAVE_TLHELP32_H
1025
+ do
1026
+ {
1027
+ snapshot = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE, 0);
1028
+ }
1029
+ while (snapshot == INVALID_HANDLE_VALUE
1030
+ && GetLastError () == ERROR_BAD_LENGTH);
1031
+
1032
+ if (snapshot != INVALID_HANDLE_VALUE)
1033
+ {
1034
+ MODULEENTRY32 entry;
1035
+ BOOL ok;
1036
+ entry.dwSize = sizeof (MODULEENTRY32);
1037
+
1038
+ for (ok = Module32First (snapshot, &entry); ok; ok = Module32Next (snapshot, &entry))
1039
+ {
1040
+ if (strcmp (filename, entry.szExePath) == 0)
1041
+ continue;
1042
+
1043
+ module_handle = (uintptr_t) entry.hModule;
1044
+ if (module_handle == 0)
1045
+ continue;
1046
+
1047
+ descriptor = backtrace_open (entry.szExePath, error_callback, data,
1048
+ NULL);
1049
+ if (descriptor < 0)
1050
+ continue;
1051
+
1052
+ coff_add (state, descriptor, error_callback, data,
1053
+ &module_fileline_fn, &module_found_sym, &found_dwarf,
1054
+ module_handle);
1055
+ if (module_found_sym)
1056
+ found_sym = 1;
1057
+ }
1058
+
1059
+ CloseHandle (snapshot);
1060
+ }
1061
+ #endif
1062
+
1063
+ #ifdef HAVE_WINDOWS_H
1064
+ nt_dll_handle = GetModuleHandleW (L"ntdll.dll");
1065
+ if (nt_dll_handle)
1066
+ {
1067
+ LDR_REGISTER_FUNCTION register_func;
1068
+ const char register_name[] = "LdrRegisterDllNotification";
1069
+ register_func = (void*) GetProcAddress (nt_dll_handle,
1070
+ register_name);
1071
+
1072
+ if (register_func)
1073
+ {
1074
+ PVOID cookie;
1075
+ struct dll_notification_context *context
1076
+ = backtrace_alloc (state,
1077
+ sizeof (struct dll_notification_context),
1078
+ error_callback, data);
1079
+
1080
+ if (context)
1081
+ {
1082
+ context->state = state;
1083
+ context->data = data;
1084
+ context->error_callback = error_callback;
1085
+
1086
+ register_func (0, &dll_notification, context, &cookie);
1087
+ }
1088
+ }
1089
+ }
1090
+ #endif /* defined(HAVE_WINDOWS_H) */
1091
+
926
1092
  if (!state->threaded)
927
1093
  {
928
1094
  if (found_sym)
@@ -1,5 +1,5 @@
1
1
  /* posix.c -- POSIX file I/O routines for the backtrace library.
2
- Copyright (C) 2012-2021 Free Software Foundation, Inc.
2
+ Copyright (C) 2012-2024 Free Software Foundation, Inc.
3
3
  Written by Ian Lance Taylor, Google.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  /* print.c -- Print the current backtrace.
2
- Copyright (C) 2012-2021 Free Software Foundation, Inc.
2
+ Copyright (C) 2012-2024 Free Software Foundation, Inc.
3
3
  Written by Ian Lance Taylor, Google.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
@@ -47,6 +47,39 @@ struct print_data
47
47
  FILE *f;
48
48
  };
49
49
 
50
+ /* Print errors to stderr. */
51
+
52
+ static void
53
+ error_callback (void *data, const char *msg, int errnum)
54
+ {
55
+ struct print_data *pdata = (struct print_data *) data;
56
+
57
+ if (pdata->state->filename != NULL)
58
+ fprintf (stderr, "%s: ", pdata->state->filename);
59
+ fprintf (stderr, "libbacktrace: %s", msg);
60
+ if (errnum > 0)
61
+ fprintf (stderr, ": %s", strerror (errnum));
62
+ fputc ('\n', stderr);
63
+ }
64
+
65
+ /* Print one level of a backtrace if we couldn't get a file or function name.
66
+ Use syminfo to try to get a symbol name. */
67
+
68
+ static void print_syminfo_callback (void *data, uintptr_t pc,
69
+ const char *symname, uintptr_t symval,
70
+ uintptr_t symsize ATTRIBUTE_UNUSED)
71
+ {
72
+ struct print_data *pdata = (struct print_data *) data;
73
+
74
+ if (symname == NULL)
75
+ fprintf (pdata->f, "0x%lx ???\n\t???:0\n", (unsigned long) pc);
76
+ else
77
+ fprintf (pdata->f, "0x%lx ???\n\t%s+0x%lx:0\n",
78
+ (unsigned long) pc,
79
+ symname,
80
+ (unsigned long) (pc - symval));
81
+ }
82
+
50
83
  /* Print one level of a backtrace. */
51
84
 
52
85
  static int
@@ -55,6 +88,13 @@ print_callback (void *data, uintptr_t pc, const char *filename, int lineno,
55
88
  {
56
89
  struct print_data *pdata = (struct print_data *) data;
57
90
 
91
+ if (function == NULL && filename == NULL)
92
+ {
93
+ backtrace_syminfo (pdata->state, pc, print_syminfo_callback,
94
+ error_callback, data);
95
+ return 0;
96
+ }
97
+
58
98
  fprintf (pdata->f, "0x%lx %s\n\t%s:%d\n",
59
99
  (unsigned long) pc,
60
100
  function == NULL ? "???" : function,
@@ -63,21 +103,6 @@ print_callback (void *data, uintptr_t pc, const char *filename, int lineno,
63
103
  return 0;
64
104
  }
65
105
 
66
- /* Print errors to stderr. */
67
-
68
- static void
69
- error_callback (void *data, const char *msg, int errnum)
70
- {
71
- struct print_data *pdata = (struct print_data *) data;
72
-
73
- if (pdata->state->filename != NULL)
74
- fprintf (stderr, "%s: ", pdata->state->filename);
75
- fprintf (stderr, "libbacktrace: %s", msg);
76
- if (errnum > 0)
77
- fprintf (stderr, ": %s", strerror (errnum));
78
- fputc ('\n', stderr);
79
- }
80
-
81
106
  /* Print a backtrace. */
82
107
 
83
108
  void __attribute__((noinline))
@@ -1,5 +1,5 @@
1
1
  /* read.c -- File views without mmap.
2
- Copyright (C) 2012-2021 Free Software Foundation, Inc.
2
+ Copyright (C) 2012-2024 Free Software Foundation, Inc.
3
3
  Written by Ian Lance Taylor, Google.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  /* simple.c -- The backtrace_simple function.
2
- Copyright (C) 2012-2021 Free Software Foundation, Inc.
2
+ Copyright (C) 2012-2024 Free Software Foundation, Inc.
3
3
  Written by Ian Lance Taylor, Google.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without