Skip to content

Commit 43609f3

Browse files
committed
Implement -d inlines support for Mach-O.
1 parent f9437fd commit 43609f3

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

src/macho.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,14 @@ class MachOObjectFile : public ObjectFile {
606606
ParseSymbols(sink->input_file().data(), nullptr, sink);
607607
break;
608608
}
609+
case DataSource::kInlines: {
610+
CheckNotObject("inlines", sink);
611+
dwarf::File dwarf;
612+
ReadDebugSectionsFromMachO(debug_file().file_data(), &dwarf, sink);
613+
ReadDWARFInlines(dwarf, sink, true);
614+
break;
615+
}
609616
case DataSource::kArchiveMembers:
610-
case DataSource::kInlines:
611617
default:
612618
THROW("Mach-O doesn't support this data source");
613619
}

tests/macho/inlines.test

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Test that -d inlines works for Mach-O binaries
2+
#
3+
# Source: tests/testdata/macho/test_inlines.c
4+
#
5+
# To regenerate test binary and dSYM (requires macOS):
6+
# mkdir -p /tmp/build && cd /tmp/build
7+
# cp $BLOATY_ROOT/tests/testdata/macho/test_inlines.c .
8+
# clang -g -O2 -c test_inlines.c -o test_inlines.o
9+
# clang -g test_inlines.o -o 02-inlines
10+
# # The dSYM bundle (02-inlines.dSYM) is created automatically by clang
11+
# cp 02-inlines $BLOATY_ROOT/tests/testdata/macho/
12+
# cp -r 02-inlines.dSYM $BLOATY_ROOT/tests/testdata/macho/
13+
#
14+
# RUN: %bloaty %S/../testdata/macho/02-inlines --debug-file=%S/../testdata/macho/02-inlines.dSYM/Contents/Resources/DWARF/02-inlines -d inlines --domain=vm | %FileCheck %s
15+
16+
# CHECK: VM SIZE
17+
# CHECK: test_inlines.c:

tests/testdata/macho/02-inlines

16.5 KB
Binary file not shown.
Binary file not shown.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Test file for inline function support in bloaty
2+
// This source generates the 02-inlines binary and dSYM for testing -d inlines
3+
4+
static inline int add(int a, int b) { return a + b; }
5+
6+
static inline int multiply(int a, int b) { return a * b; }
7+
8+
int external_call(int x) { return add(x, 5) + multiply(x, 2); }
9+
10+
int main(void) {
11+
int x = 10;
12+
int y = external_call(x);
13+
return y;
14+
}

0 commit comments

Comments
 (0)