Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Unified Diff: tracing/bin/symbolize_trace_macho_reader.py

Issue 2698543003: Use absolute pcs and load locations to symbolize on macOS. (Closed)
Patch Set: comments from dskiba. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tracing/bin/symbolize_trace ('k') | tracing/bin/symbolize_trace_macho_reader_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tracing/bin/symbolize_trace_macho_reader.py
diff --git a/tracing/bin/symbolize_trace_macho_reader.py b/tracing/bin/symbolize_trace_macho_reader.py
new file mode 100644
index 0000000000000000000000000000000000000000..ea8a63666716deb55601b05a7cb3af1bd9c7313a
--- /dev/null
+++ b/tracing/bin/symbolize_trace_macho_reader.py
@@ -0,0 +1,26 @@
+# Copyright 2017 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import re
+import subprocess
+
+
+def ReadMachOTextLoadAddress(file_name):
+ """
+ This function returns the load address of the TEXT segment of a Mach-O file.
+ """
+ regex = re.compile(r".* vmaddr 0x([\dabcdef]*)")
+ cmd = ["otool", "-l", file_name]
+ output = subprocess.check_output(cmd).split('\n')
+ for i in range(len(output) - 3):
+ # It's possible to use a regex here instead, but these conditionals are much
+ # clearer.
+ if ("cmd LC_SEGMENT_64" in output[i] and
+ "cmdsize" in output[i + 1] and
+ "segname __TEXT" in output[i + 2] and
+ "vmaddr" in output[i + 3]):
+ result = regex.match(output[i + 3])
+ assert result
+ return int(result.group(1), 16)
+ return None
« no previous file with comments | « tracing/bin/symbolize_trace ('k') | tracing/bin/symbolize_trace_macho_reader_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698