pf2 0.8.0 → 1.0.0.alpha1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/README.md +20 -4
  4. data/Rakefile +1 -0
  5. data/doc/development.md +17 -0
  6. data/examples/mandelbrot.rb +69 -0
  7. data/examples/mandelbrot_ractor.rb +77 -0
  8. data/ext/pf2/backtrace_state.c +10 -0
  9. data/ext/pf2/backtrace_state.h +10 -0
  10. data/ext/pf2/configuration.c +90 -0
  11. data/ext/pf2/configuration.h +23 -0
  12. data/ext/pf2/debug.h +12 -0
  13. data/ext/pf2/extconf.rb +23 -6
  14. data/ext/pf2/pf2.c +17 -0
  15. data/ext/pf2/pf2.h +8 -0
  16. data/ext/pf2/ringbuffer.c +74 -0
  17. data/ext/pf2/ringbuffer.h +24 -0
  18. data/ext/pf2/sample.c +76 -0
  19. data/ext/pf2/sample.h +26 -0
  20. data/ext/pf2/serializer.c +377 -0
  21. data/ext/pf2/serializer.h +58 -0
  22. data/ext/pf2/session.c +394 -0
  23. data/ext/pf2/session.h +56 -0
  24. data/lib/pf2/cli.rb +25 -11
  25. data/lib/pf2/reporter/annotate.rb +101 -0
  26. data/lib/pf2/reporter/firefox_profiler_ser2.rb +17 -13
  27. data/lib/pf2/reporter/stack_weaver.rb +8 -0
  28. data/lib/pf2/reporter.rb +1 -1
  29. data/lib/pf2/version.rb +1 -1
  30. data/lib/pf2.rb +1 -1
  31. data/vendor/libbacktrace/.gitignore +5 -0
  32. data/{crates/backtrace-sys2/src → vendor}/libbacktrace/README.md +1 -1
  33. data/{crates/backtrace-sys2/src → vendor}/libbacktrace/configure +23 -0
  34. data/{crates/backtrace-sys2/src → vendor}/libbacktrace/configure.ac +10 -0
  35. data/{crates/backtrace-sys2/src → vendor}/libbacktrace/dwarf.c +199 -15
  36. data/{crates/backtrace-sys2/src → vendor}/libbacktrace/elf.c +20 -14
  37. data/{crates/backtrace-sys2/src → vendor}/libbacktrace/fileline.c +2 -2
  38. data/{crates/backtrace-sys2/src → vendor}/libbacktrace/macho.c +2 -2
  39. data/{crates/backtrace-sys2/src → vendor}/libbacktrace/pecoff.c +2 -2
  40. metadata +111 -111
  41. data/Cargo.lock +0 -630
  42. data/Cargo.toml +0 -3
  43. data/crates/backtrace-sys2/.gitignore +0 -1
  44. data/crates/backtrace-sys2/Cargo.toml +0 -9
  45. data/crates/backtrace-sys2/build.rs +0 -45
  46. data/crates/backtrace-sys2/src/lib.rs +0 -5
  47. data/crates/backtrace-sys2/src/libbacktrace/.gitignore +0 -15
  48. data/ext/pf2/Cargo.toml +0 -25
  49. data/ext/pf2/build.rs +0 -10
  50. data/ext/pf2/src/backtrace.rs +0 -127
  51. data/ext/pf2/src/lib.rs +0 -22
  52. data/ext/pf2/src/profile.rs +0 -69
  53. data/ext/pf2/src/profile_serializer.rs +0 -241
  54. data/ext/pf2/src/ringbuffer.rs +0 -150
  55. data/ext/pf2/src/ruby_c_api_helper.c +0 -6
  56. data/ext/pf2/src/ruby_init.rs +0 -40
  57. data/ext/pf2/src/ruby_internal_apis.rs +0 -77
  58. data/ext/pf2/src/sample.rs +0 -67
  59. data/ext/pf2/src/scheduler.rs +0 -10
  60. data/ext/pf2/src/serialization/profile.rs +0 -48
  61. data/ext/pf2/src/serialization/serializer.rs +0 -329
  62. data/ext/pf2/src/serialization.rs +0 -2
  63. data/ext/pf2/src/session/configuration.rs +0 -114
  64. data/ext/pf2/src/session/new_thread_watcher.rs +0 -80
  65. data/ext/pf2/src/session/ruby_object.rs +0 -90
  66. data/ext/pf2/src/session.rs +0 -248
  67. data/ext/pf2/src/siginfo_t.c +0 -5
  68. data/ext/pf2/src/signal_scheduler.rs +0 -201
  69. data/ext/pf2/src/signal_scheduler_unsupported_platform.rs +0 -39
  70. data/ext/pf2/src/timer_thread_scheduler.rs +0 -179
  71. data/ext/pf2/src/util.rs +0 -31
  72. data/lib/pf2/reporter/firefox_profiler.rb +0 -397
  73. data/rust-toolchain.toml +0 -2
  74. data/rustfmt.toml +0 -1
  75. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/Isaac.Newton-Opticks.txt +0 -0
  76. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/LICENSE +0 -0
  77. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/Makefile.am +0 -0
  78. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/Makefile.in +0 -0
  79. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/aclocal.m4 +0 -0
  80. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/alloc.c +0 -0
  81. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/allocfail.c +0 -0
  82. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/allocfail.sh +0 -0
  83. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/atomic.c +0 -0
  84. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/backtrace-supported.h.in +0 -0
  85. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/backtrace.c +0 -0
  86. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/backtrace.h +0 -0
  87. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/btest.c +0 -0
  88. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/compile +0 -0
  89. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/config/enable.m4 +0 -0
  90. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/config/lead-dot.m4 +0 -0
  91. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/config/libtool.m4 +0 -0
  92. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/config/ltoptions.m4 +0 -0
  93. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/config/ltsugar.m4 +0 -0
  94. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/config/ltversion.m4 +0 -0
  95. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/config/lt~obsolete.m4 +0 -0
  96. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/config/multi.m4 +0 -0
  97. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/config/override.m4 +0 -0
  98. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/config/unwind_ipinfo.m4 +0 -0
  99. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/config/warnings.m4 +0 -0
  100. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/config.guess +0 -0
  101. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/config.h.in +0 -0
  102. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/config.sub +0 -0
  103. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/edtest.c +0 -0
  104. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/edtest2.c +0 -0
  105. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/filenames.h +0 -0
  106. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/filetype.awk +0 -0
  107. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/install-debuginfo-for-buildid.sh.in +0 -0
  108. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/install-sh +0 -0
  109. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/instrumented_alloc.c +0 -0
  110. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/internal.h +0 -0
  111. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/ltmain.sh +0 -0
  112. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/missing +0 -0
  113. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/mmap.c +0 -0
  114. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/mmapio.c +0 -0
  115. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/move-if-change +0 -0
  116. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/mtest.c +0 -0
  117. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/nounwind.c +0 -0
  118. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/posix.c +0 -0
  119. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/print.c +0 -0
  120. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/read.c +0 -0
  121. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/simple.c +0 -0
  122. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/sort.c +0 -0
  123. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/state.c +0 -0
  124. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/stest.c +0 -0
  125. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/test-driver +0 -0
  126. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/test_format.c +0 -0
  127. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/testlib.c +0 -0
  128. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/testlib.h +0 -0
  129. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/ttest.c +0 -0
  130. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/unittest.c +0 -0
  131. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/unknown.c +0 -0
  132. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/xcoff.c +0 -0
  133. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/xztest.c +0 -0
  134. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/zstdtest.c +0 -0
  135. /data/{crates/backtrace-sys2/src → vendor}/libbacktrace/ztest.c +0 -0
@@ -2,6 +2,14 @@
2
2
 
3
3
  module Pf2
4
4
  module Reporter
5
+ # "Weaves" the native stack into the Ruby stack.
6
+ #
7
+ # Strategy:
8
+ # - Split the stack into Ruby and Native parts
9
+ # - Start from the root of the Native stack
10
+ # - Dig in to the native stack until we hit a rb_vm_exec(), which marks a call into Ruby code
11
+ # - Switch to Ruby stack. Keep digging until we hit a Cfunc call, then switch back to Native stack
12
+ # - Repeat until we consume the entire stack
5
13
  class StackWeaver
6
14
  def initialize(profile)
7
15
  @profile = profile
data/lib/pf2/reporter.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative './reporter/annotate'
3
4
  require_relative './reporter/stack_weaver'
4
- require_relative './reporter/firefox_profiler'
5
5
  require_relative './reporter/firefox_profiler_ser2'
data/lib/pf2/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pf2
4
- VERSION = '0.8.0'
4
+ VERSION = '1.0.0.alpha1'
5
5
  end
data/lib/pf2.rb CHANGED
@@ -8,7 +8,7 @@ module Pf2
8
8
  class Error < StandardError; end
9
9
 
10
10
  def self.start(...)
11
- @@session = Pf2::Session.new(...)
11
+ @@session = Pf2c::Session.new(...)
12
12
  @@session.start
13
13
  end
14
14
 
@@ -0,0 +1,5 @@
1
+ *~
2
+ *.o
3
+ *.lo
4
+ *.a
5
+ *.la
@@ -14,7 +14,7 @@ occurs or to gather detailed profiling information.
14
14
  In general the functions provided by this library are async-signal-safe,
15
15
  meaning that they may be safely called from a signal handler.
16
16
  That said, on systems that use `dl_iterate_phdr`, such as GNU/Linux,
17
- gitthe first call to a libbacktrace function will call `dl_iterate_phdr`,
17
+ the first call to a libbacktrace function will call `dl_iterate_phdr`,
18
18
  which is not in general async-signal-safe. Therefore, programs
19
19
  that call libbacktrace from a signal handler should ensure that they
20
20
  make an initial call from outside of a signal handler.
@@ -12209,6 +12209,29 @@ else
12209
12209
  if test -n "${with_target_subdir}"; then
12210
12210
  case "${host}" in
12211
12211
  hppa*-*-hpux*) libbacktrace_cv_sys_sync=no ;;
12212
+ arm*-*-eabi*)
12213
+ # Older versions of the Arm architecture lack the necessary instructions
12214
+ # for these constructs, so check whether we can use them.
12215
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
12216
+ /* end confdefs.h. */
12217
+ int i;
12218
+ int
12219
+ main ()
12220
+ {
12221
+ __sync_bool_compare_and_swap (&i, i, i);
12222
+ __sync_lock_test_and_set (&i, 1);
12223
+ __sync_lock_release (&i);
12224
+ ;
12225
+ return 0;
12226
+ }
12227
+ _ACEOF
12228
+ if ac_fn_c_try_link "$LINENO"; then :
12229
+ libbacktrace_cv_sys_sync=yes
12230
+ else
12231
+ libbacktrace_cv_sys_sync=no
12232
+ fi
12233
+ rm -f core conftest.err conftest.$ac_objext \
12234
+ conftest$ac_exeext conftest.$ac_ext;;
12212
12235
  *) libbacktrace_cv_sys_sync=yes ;;
12213
12236
  esac
12214
12237
  else
@@ -189,6 +189,16 @@ AC_CACHE_CHECK([__sync extensions],
189
189
  [if test -n "${with_target_subdir}"; then
190
190
  case "${host}" in
191
191
  hppa*-*-hpux*) libbacktrace_cv_sys_sync=no ;;
192
+ arm*-*-eabi*)
193
+ # Older versions of the Arm architecture lack the necessary instructions
194
+ # for these constructs, so check whether we can use them.
195
+ AC_LINK_IFELSE(
196
+ [AC_LANG_PROGRAM([int i;],
197
+ [__sync_bool_compare_and_swap (&i, i, i);
198
+ __sync_lock_test_and_set (&i, 1);
199
+ __sync_lock_release (&i);])],
200
+ [libbacktrace_cv_sys_sync=yes],
201
+ [libbacktrace_cv_sys_sync=no]);;
192
202
  *) libbacktrace_cv_sys_sync=yes ;;
193
203
  esac
194
204
  else
@@ -1610,6 +1610,194 @@ unit_addrs_search (const void *vkey, const void *ventry)
1610
1610
  return 0;
1611
1611
  }
1612
1612
 
1613
+ /* Fill in overlapping ranges as needed. This is a subroutine of
1614
+ resolve_unit_addrs_overlap. */
1615
+
1616
+ static int
1617
+ resolve_unit_addrs_overlap_walk (struct backtrace_state *state,
1618
+ size_t *pfrom, size_t *pto,
1619
+ struct unit_addrs *enclosing,
1620
+ struct unit_addrs_vector *old_vec,
1621
+ backtrace_error_callback error_callback,
1622
+ void *data,
1623
+ struct unit_addrs_vector *new_vec)
1624
+ {
1625
+ struct unit_addrs *old_addrs;
1626
+ size_t old_count;
1627
+ struct unit_addrs *new_addrs;
1628
+ size_t from;
1629
+ size_t to;
1630
+
1631
+ old_addrs = (struct unit_addrs *) old_vec->vec.base;
1632
+ old_count = old_vec->count;
1633
+ new_addrs = (struct unit_addrs *) new_vec->vec.base;
1634
+
1635
+ for (from = *pfrom, to = *pto; from < old_count; from++, to++)
1636
+ {
1637
+ /* If we are in the scope of a larger range that can no longer
1638
+ cover any further ranges, return back to the caller. */
1639
+
1640
+ if (enclosing != NULL
1641
+ && enclosing->high <= old_addrs[from].low)
1642
+ {
1643
+ *pfrom = from;
1644
+ *pto = to;
1645
+ return 1;
1646
+ }
1647
+
1648
+ new_addrs[to] = old_addrs[from];
1649
+
1650
+ /* If we are in scope of a larger range, fill in any gaps
1651
+ between this entry and the next one.
1652
+
1653
+ There is an extra entry at the end of the vector, so it's
1654
+ always OK to refer to from + 1. */
1655
+
1656
+ if (enclosing != NULL
1657
+ && enclosing->high > old_addrs[from].high
1658
+ && old_addrs[from].high < old_addrs[from + 1].low)
1659
+ {
1660
+ void *grew;
1661
+ size_t new_high;
1662
+
1663
+ grew = backtrace_vector_grow (state, sizeof (struct unit_addrs),
1664
+ error_callback, data, &new_vec->vec);
1665
+ if (grew == NULL)
1666
+ return 0;
1667
+ new_addrs = (struct unit_addrs *) new_vec->vec.base;
1668
+ to++;
1669
+ new_addrs[to].low = old_addrs[from].high;
1670
+ new_high = old_addrs[from + 1].low;
1671
+ if (enclosing->high < new_high)
1672
+ new_high = enclosing->high;
1673
+ new_addrs[to].high = new_high;
1674
+ new_addrs[to].u = enclosing->u;
1675
+ }
1676
+
1677
+ /* If this range has a larger scope than the next one, use it to
1678
+ fill in any gaps. */
1679
+
1680
+ if (old_addrs[from].high > old_addrs[from + 1].high)
1681
+ {
1682
+ *pfrom = from + 1;
1683
+ *pto = to + 1;
1684
+ if (!resolve_unit_addrs_overlap_walk (state, pfrom, pto,
1685
+ &old_addrs[from], old_vec,
1686
+ error_callback, data, new_vec))
1687
+ return 0;
1688
+ from = *pfrom;
1689
+ to = *pto;
1690
+
1691
+ /* Undo the increment the loop is about to do. */
1692
+ from--;
1693
+ to--;
1694
+ }
1695
+ }
1696
+
1697
+ if (enclosing == NULL)
1698
+ {
1699
+ struct unit_addrs *pa;
1700
+
1701
+ /* Add trailing entry. */
1702
+
1703
+ pa = ((struct unit_addrs *)
1704
+ backtrace_vector_grow (state, sizeof (struct unit_addrs),
1705
+ error_callback, data, &new_vec->vec));
1706
+ if (pa == NULL)
1707
+ return 0;
1708
+ pa->low = 0;
1709
+ --pa->low;
1710
+ pa->high = pa->low;
1711
+ pa->u = NULL;
1712
+
1713
+ new_vec->count = to;
1714
+ }
1715
+
1716
+ return 1;
1717
+ }
1718
+
1719
+ /* It is possible for the unit_addrs list to contain overlaps, as in
1720
+
1721
+ 10: low == 10, high == 20, unit 1
1722
+ 11: low == 12, high == 15, unit 2
1723
+ 12: low == 20, high == 30, unit 1
1724
+
1725
+ In such a case, for pc == 17, a search using units_addr_search will
1726
+ return entry 11. However, pc == 17 doesn't fit in that range. We
1727
+ actually want range 10.
1728
+
1729
+ It seems that in general we might have an arbitrary number of
1730
+ ranges in between 10 and 12.
1731
+
1732
+ To handle this we look for cases where range R1 is followed by
1733
+ range R2 such that R2 is a strict subset of R1. In such cases we
1734
+ insert a new range R3 following R2 that fills in the remainder of
1735
+ the address space covered by R1. That lets a relatively simple
1736
+ search find the correct range.
1737
+
1738
+ These overlaps can occur because of the range merging we do in
1739
+ add_unit_addr. When the linker de-duplicates functions, it can
1740
+ leave behind an address range that refers to the address range of
1741
+ the retained duplicate. If the retained duplicate address range is
1742
+ merged with others, then after sorting we can see overlapping
1743
+ address ranges.
1744
+
1745
+ See https://github.com/ianlancetaylor/libbacktrace/issues/137. */
1746
+
1747
+ static int
1748
+ resolve_unit_addrs_overlap (struct backtrace_state *state,
1749
+ backtrace_error_callback error_callback,
1750
+ void *data, struct unit_addrs_vector *addrs_vec)
1751
+ {
1752
+ struct unit_addrs *addrs;
1753
+ size_t count;
1754
+ int found;
1755
+ struct unit_addrs *entry;
1756
+ size_t i;
1757
+ struct unit_addrs_vector new_vec;
1758
+ void *grew;
1759
+ size_t from;
1760
+ size_t to;
1761
+
1762
+ addrs = (struct unit_addrs *) addrs_vec->vec.base;
1763
+ count = addrs_vec->count;
1764
+
1765
+ if (count == 0)
1766
+ return 1;
1767
+
1768
+ /* Optimistically assume that overlaps are rare. */
1769
+ found = 0;
1770
+ entry = addrs;
1771
+ for (i = 0; i < count - 1; i++)
1772
+ {
1773
+ if (entry->low < (entry + 1)->low
1774
+ && entry->high > (entry + 1)->high)
1775
+ {
1776
+ found = 1;
1777
+ break;
1778
+ }
1779
+ entry++;
1780
+ }
1781
+ if (!found)
1782
+ return 1;
1783
+
1784
+ memset (&new_vec, 0, sizeof new_vec);
1785
+ grew = backtrace_vector_grow (state,
1786
+ count * sizeof (struct unit_addrs),
1787
+ error_callback, data, &new_vec.vec);
1788
+ if (grew == NULL)
1789
+ return 0;
1790
+
1791
+ from = 0;
1792
+ to = 0;
1793
+ resolve_unit_addrs_overlap_walk (state, &from, &to, NULL, addrs_vec,
1794
+ error_callback, data, &new_vec);
1795
+ backtrace_vector_free (state, &addrs_vec->vec, error_callback, data);
1796
+ *addrs_vec = new_vec;
1797
+
1798
+ return 1;
1799
+ }
1800
+
1613
1801
  /* Sort the line vector by PC. We want a stable sort here to maintain
1614
1802
  the order of lines for the same PC values. Since the sequence is
1615
1803
  being sorted in place, their addresses cannot be relied on to
@@ -3314,7 +3502,7 @@ read_line_info (struct backtrace_state *state, struct dwarf_data *ddata,
3314
3502
 
3315
3503
  if (vec.count == 0)
3316
3504
  {
3317
- /* This is not a failure in the sense of a generating an error,
3505
+ /* This is not a failure in the sense of generating an error,
3318
3506
  but it is a failure in that sense that we have no useful
3319
3507
  information. */
3320
3508
  goto fail;
@@ -4300,11 +4488,7 @@ build_dwarf_data (struct backtrace_state *state,
4300
4488
  void *data)
4301
4489
  {
4302
4490
  struct unit_addrs_vector addrs_vec;
4303
- struct unit_addrs *addrs;
4304
- size_t addrs_count;
4305
4491
  struct unit_vector units_vec;
4306
- struct unit **units;
4307
- size_t units_count;
4308
4492
  struct dwarf_data *fdata;
4309
4493
 
4310
4494
  if (!build_address_map (state, base_address, dwarf_sections, is_bigendian,
@@ -4316,12 +4500,12 @@ build_dwarf_data (struct backtrace_state *state,
4316
4500
  return NULL;
4317
4501
  if (!backtrace_vector_release (state, &units_vec.vec, error_callback, data))
4318
4502
  return NULL;
4319
- addrs = (struct unit_addrs *) addrs_vec.vec.base;
4320
- units = (struct unit **) units_vec.vec.base;
4321
- addrs_count = addrs_vec.count;
4322
- units_count = units_vec.count;
4323
- backtrace_qsort (addrs, addrs_count, sizeof (struct unit_addrs),
4324
- unit_addrs_compare);
4503
+
4504
+ backtrace_qsort ((struct unit_addrs *) addrs_vec.vec.base, addrs_vec.count,
4505
+ sizeof (struct unit_addrs), unit_addrs_compare);
4506
+ if (!resolve_unit_addrs_overlap (state, error_callback, data, &addrs_vec))
4507
+ return NULL;
4508
+
4325
4509
  /* No qsort for units required, already sorted. */
4326
4510
 
4327
4511
  fdata = ((struct dwarf_data *)
@@ -4333,10 +4517,10 @@ build_dwarf_data (struct backtrace_state *state,
4333
4517
  fdata->next = NULL;
4334
4518
  fdata->altlink = altlink;
4335
4519
  fdata->base_address = base_address;
4336
- fdata->addrs = addrs;
4337
- fdata->addrs_count = addrs_count;
4338
- fdata->units = units;
4339
- fdata->units_count = units_count;
4520
+ fdata->addrs = (struct unit_addrs *) addrs_vec.vec.base;
4521
+ fdata->addrs_count = addrs_vec.count;
4522
+ fdata->units = (struct unit **) units_vec.vec.base;
4523
+ fdata->units_count = units_vec.count;
4340
4524
  fdata->dwarf_sections = *dwarf_sections;
4341
4525
  fdata->is_bigendian = is_bigendian;
4342
4526
  memset (&fdata->fvec, 0, sizeof fdata->fvec);
@@ -1147,7 +1147,10 @@ elf_fetch_bits (const unsigned char **ppin, const unsigned char *pinend,
1147
1147
  next = __builtin_bswap32 (next);
1148
1148
  #endif
1149
1149
  #else
1150
- next = pin[0] | (pin[1] << 8) | (pin[2] << 16) | (pin[3] << 24);
1150
+ next = ((uint32_t)pin[0]
1151
+ | ((uint32_t)pin[1] << 8)
1152
+ | ((uint32_t)pin[2] << 16)
1153
+ | ((uint32_t)pin[3] << 24));
1151
1154
  #endif
1152
1155
 
1153
1156
  val |= (uint64_t)next << bits;
@@ -1198,7 +1201,10 @@ elf_fetch_bits_backward (const unsigned char **ppin,
1198
1201
  next = __builtin_bswap32 (next);
1199
1202
  #endif
1200
1203
  #else
1201
- next = pin[0] | (pin[1] << 8) | (pin[2] << 16) | (pin[3] << 24);
1204
+ next = ((uint32_t)pin[0]
1205
+ | ((uint32_t)pin[1] << 8)
1206
+ | ((uint32_t)pin[2] << 16)
1207
+ | ((uint32_t)pin[3] << 24));
1202
1208
  #endif
1203
1209
 
1204
1210
  val <<= 32;
@@ -5872,10 +5878,10 @@ elf_uncompress_lzma_block (const unsigned char *compressed,
5872
5878
  /* The byte at compressed[off] is ignored for some
5873
5879
  reason. */
5874
5880
 
5875
- code = ((compressed[off + 1] << 24)
5876
- + (compressed[off + 2] << 16)
5877
- + (compressed[off + 3] << 8)
5878
- + compressed[off + 4]);
5881
+ code = (((uint32_t)compressed[off + 1] << 24)
5882
+ + ((uint32_t)compressed[off + 2] << 16)
5883
+ + ((uint32_t)compressed[off + 3] << 8)
5884
+ + (uint32_t)compressed[off + 4]);
5879
5885
  off += 5;
5880
5886
 
5881
5887
  /* This is the main LZMA decode loop. */
@@ -6198,10 +6204,10 @@ elf_uncompress_lzma_block (const unsigned char *compressed,
6198
6204
  return 0;
6199
6205
  }
6200
6206
  computed_crc = elf_crc32 (0, uncompressed, uncompressed_offset);
6201
- stream_crc = (compressed[off]
6202
- | (compressed[off + 1] << 8)
6203
- | (compressed[off + 2] << 16)
6204
- | (compressed[off + 3] << 24));
6207
+ stream_crc = ((uint32_t)compressed[off]
6208
+ | ((uint32_t)compressed[off + 1] << 8)
6209
+ | ((uint32_t)compressed[off + 2] << 16)
6210
+ | ((uint32_t)compressed[off + 3] << 24));
6205
6211
  if (computed_crc != stream_crc)
6206
6212
  {
6207
6213
  elf_uncompress_failed ();
@@ -6336,10 +6342,10 @@ elf_uncompress_lzma (struct backtrace_state *state,
6336
6342
 
6337
6343
  /* Before that is the size of the index field, which precedes the
6338
6344
  footer. */
6339
- index_size = (compressed[offset - 4]
6340
- | (compressed[offset - 3] << 8)
6341
- | (compressed[offset - 2] << 16)
6342
- | (compressed[offset - 1] << 24));
6345
+ index_size = ((size_t)compressed[offset - 4]
6346
+ | ((size_t)compressed[offset - 3] << 8)
6347
+ | ((size_t)compressed[offset - 2] << 16)
6348
+ | ((size_t)compressed[offset - 1] << 24));
6343
6349
  index_size = (index_size + 1) * 4;
6344
6350
  offset -= 4;
6345
6351
 
@@ -48,8 +48,8 @@ POSSIBILITY OF SUCH DAMAGE. */
48
48
  #endif
49
49
 
50
50
  #ifdef HAVE_WINDOWS_H
51
- #ifndef WIN32_MEAN_AND_LEAN
52
- #define WIN32_MEAN_AND_LEAN
51
+ #ifndef WIN32_LEAN_AND_MEAN
52
+ #define WIN32_LEAN_AND_MEAN
53
53
  #endif
54
54
 
55
55
  #ifndef NOMINMAX
@@ -306,9 +306,9 @@ static const char * const dwarf_section_names[DEBUG_MAX] =
306
306
  "__debug_abbrev",
307
307
  "__debug_ranges",
308
308
  "__debug_str",
309
- "", /* DEBUG_ADDR */
309
+ "__debug_addr",
310
310
  "__debug_str_offs",
311
- "", /* DEBUG_LINE_STR */
311
+ "__debug_line_str",
312
312
  "__debug_rnglists"
313
313
  };
314
314
 
@@ -40,8 +40,8 @@ POSSIBILITY OF SUCH DAMAGE. */
40
40
  #include "internal.h"
41
41
 
42
42
  #ifdef HAVE_WINDOWS_H
43
- #ifndef WIN32_MEAN_AND_LEAN
44
- #define WIN32_MEAN_AND_LEAN
43
+ #ifndef WIN32_LEAN_AND_MEAN
44
+ #define WIN32_LEAN_AND_MEAN
45
45
  #endif
46
46
 
47
47
  #ifndef NOMINMAX