summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Schwerin <schwerin@mongodb.com>2015-12-28 12:48:58 -0500
committerAndy Schwerin <schwerin@mongodb.com>2015-12-29 14:02:27 -0500
commit706d2e0a94c57d5c4a01a4787d78d413f134441e (patch)
tree0588c4de787ec0f4c618522d9aca0a252b17dd96
parent752bf605cf827d561687ae155d8349a717b3d723 (diff)
downloadmongo-706d2e0a94c57d5c4a01a4787d78d413f134441e.tar.gz
SERVER-21934 Add extra information to OSX stack dumps to support ASLR.
-rw-r--r--src/mongo/util/stacktrace_posix.cpp43
1 files changed, 35 insertions, 8 deletions
diff --git a/src/mongo/util/stacktrace_posix.cpp b/src/mongo/util/stacktrace_posix.cpp
index 5515e3d7fd9..17d33f8c3f5 100644
--- a/src/mongo/util/stacktrace_posix.cpp
+++ b/src/mongo/util/stacktrace_posix.cpp
@@ -455,6 +455,15 @@ uint32_t lcType(const char* lcCurr) {
return cmd->cmd;
}
+template <typename SegmentCommandType>
+bool maybeAppendLoadAddr(BSONObjBuilder* soInfo, const SegmentCommandType* segmentCommand) {
+ if (StringData(SEG_TEXT) != segmentCommand->segname) {
+ return false;
+ }
+ *soInfo << "vmaddr" << integerToHex(segmentCommand->vmaddr);
+ return true;
+}
+
void addOSComponentsToSoMap(BSONObjBuilder* soMap) {
const uint32_t numImages = _dyld_image_count();
BSONArrayBuilder soList(soMap->subarrayStart("somap"));
@@ -479,16 +488,34 @@ void addOSComponentsToSoMap(BSONObjBuilder* soMap) {
const char* const loadCommandsBegin = reinterpret_cast<const char*>(header) + headerSize;
const char* const loadCommandsEnd = loadCommandsBegin + header->sizeofcmds;
- // Search the "load command" data in the Mach object for the entry
- // encoding the UUID of the object.
+ // Search the "load command" data in the Mach object for the entry encoding the UUID of the
+ // object, and for the __TEXT segment. Adding the "vmaddr" field of the __TEXT segment load
+ // command of an executable or dylib to an offset in that library provides an address
+ // suitable to passing to atos or llvm-symbolizer for symbolization.
+ //
+ // See, for example, http://lldb.llvm.org/symbolication.html.
+ bool foundTextSegment = false;
for (const char* lcCurr = loadCommandsBegin; lcCurr < loadCommandsEnd;
lcCurr = lcNext(lcCurr)) {
- if (LC_UUID != lcType(lcCurr))
- continue;
-
- const uuid_command* uuidCmd = reinterpret_cast<const uuid_command*>(lcCurr);
- soInfo << "buildId" << toHex(uuidCmd->uuid, 16);
- break;
+ switch (lcType(lcCurr)) {
+ case LC_UUID: {
+ const auto uuidCmd = reinterpret_cast<const uuid_command*>(lcCurr);
+ soInfo << "buildId" << toHex(uuidCmd->uuid, 16);
+ break;
+ }
+ case LC_SEGMENT_64:
+ if (!foundTextSegment) {
+ foundTextSegment = maybeAppendLoadAddr(
+ &soInfo, reinterpret_cast<const segment_command_64*>(lcCurr));
+ }
+ break;
+ case LC_SEGMENT:
+ if (!foundTextSegment) {
+ foundTextSegment = maybeAppendLoadAddr(
+ &soInfo, reinterpret_cast<const segment_command*>(lcCurr));
+ }
+ break;
+ }
}
}
}