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

Unified Diff: tracing/bin/symbolize_trace_macho_reader.py

Issue 2698543003: Use absolute pcs and load locations to symbolize on macOS. (Closed)
Patch Set: Extract load address of a binary from otool. 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
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)
DmitrySkiba 2017/02/16 21:19:46 Will int be always enough?
erikchen 2017/02/16 21:32:18 """ In Python 2, Integers will automatically swit
DmitrySkiba 2017/02/16 21:38:48 Acknowledged.
+ return None

Powered by Google App Engine
This is Rietveld 408576698