summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2017-11-28 10:59:33 -0800
committerChristopher Ferris <cferris@google.com>2017-11-28 10:59:33 -0800
commita141709b212daef7b6087b0307b638c4cb8a93d7 (patch)
tree3fffe89d01e7c132bc175009e1990a7ceb004ca7
parent8055ea44de477a1e0e5aa7e8fd0d4c835a1c0bf5 (diff)
downloadsystem_core-a141709b212daef7b6087b0307b638c4cb8a93d7.tar.gz
system_core-a141709b212daef7b6087b0307b638c4cb8a93d7.tar.bz2
system_core-a141709b212daef7b6087b0307b638c4cb8a93d7.zip
Add way to specify an offset in an elf file.
This is to support the ability to dump an elf embedded in an apk. Test: Ran unwind_info on a file, then ran it on an apk with an offset. Change-Id: I8f23f4bdaadfd3665900bdd45d50cb270e2e0eed
-rw-r--r--libunwindstack/tools/unwind_info.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/libunwindstack/tools/unwind_info.cpp b/libunwindstack/tools/unwind_info.cpp
index 77f3bb235..a00b2ee48 100644
--- a/libunwindstack/tools/unwind_info.cpp
+++ b/libunwindstack/tools/unwind_info.cpp
@@ -19,6 +19,7 @@
#include <fcntl.h>
#include <inttypes.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
@@ -102,12 +103,12 @@ void DumpDwarfSection(ElfInterface* interface, DwarfSection* section, uint64_t l
}
}
-int GetElfInfo(const char* file) {
+int GetElfInfo(const char* file, uint64_t offset) {
// Send all log messages to stdout.
log_to_stdout(true);
MemoryFileAtOffset* memory = new MemoryFileAtOffset;
- if (!memory->Init(file, 0)) {
+ if (!memory->Init(file, offset)) {
// Initializatation failed.
printf("Failed to init\n");
return 1;
@@ -164,8 +165,12 @@ int GetElfInfo(const char* file) {
} // namespace unwindstack
int main(int argc, char** argv) {
- if (argc != 2) {
- printf("Need to pass the name of an elf file to the program.\n");
+ if (argc != 2 && argc != 3) {
+ printf("Usage: unwind_info ELF_FILE [OFFSET]\n");
+ printf(" ELF_FILE\n");
+ printf(" The path to an elf file.\n");
+ printf(" OFFSET\n");
+ printf(" Use the offset into the ELF file as the beginning of the elf.\n");
return 1;
}
@@ -179,5 +184,15 @@ int main(int argc, char** argv) {
return 1;
}
- return unwindstack::GetElfInfo(argv[1]);
+ uint64_t offset = 0;
+ if (argc == 3) {
+ char* end;
+ offset = strtoull(argv[2], &end, 16);
+ if (*end != '\0') {
+ printf("Malformed OFFSET value: %s\n", argv[2]);
+ return 1;
+ }
+ }
+
+ return unwindstack::GetElfInfo(argv[1], offset);
}