Make the library usable as a library.
- Add namespace unwindstack everywhere so that it's easier for other
code to use the library.
- Move some of the header files into include/unwindstack so that they
can be exposed.
- Modify the headers so that only a limited number need to be exposed.
- Update the tools to use the new headers.
- Add a GetLoadBias() call on the Elf object. This prevents the need
to get the interface object out of the Elf object.
- Move the GetRelPc() call out of the Reg class, to the Elf class. It's
not always the case that a Reg object will be around when you want to
get a relative pc. The tests for this moved to ElfTest.cpp.
Bug: 23762183
Test: Unit tests pass.
Change-Id: Iac609dac1dd90ed83d1a1e24ff2579c96c023bc3
diff --git a/libunwindstack/tools/unwind.cpp b/libunwindstack/tools/unwind.cpp
index 34cd1ce..642105a 100644
--- a/libunwindstack/tools/unwind.cpp
+++ b/libunwindstack/tools/unwind.cpp
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+#include <elf.h>
#include <errno.h>
#include <inttypes.h>
#include <signal.h>
@@ -27,10 +28,11 @@
#include <string>
-#include "Elf.h"
-#include "Maps.h"
-#include "Memory.h"
-#include "Regs.h"
+#include <unwindstack/Elf.h>
+#include <unwindstack/MapInfo.h>
+#include <unwindstack/Maps.h>
+#include <unwindstack/Memory.h>
+#include <unwindstack/Regs.h>
static bool Attach(pid_t pid) {
if (ptrace(PTRACE_ATTACH, pid, 0, 0) == -1) {
@@ -54,14 +56,14 @@
}
void DoUnwind(pid_t pid) {
- RemoteMaps remote_maps(pid);
+ unwindstack::RemoteMaps remote_maps(pid);
if (!remote_maps.Parse()) {
printf("Failed to parse map data.\n");
return;
}
uint32_t machine_type;
- Regs* regs = Regs::RemoteGet(pid, &machine_type);
+ unwindstack::Regs* regs = unwindstack::Regs::RemoteGet(pid, &machine_type);
if (regs == nullptr) {
printf("Unable to get remote reg data\n");
return;
@@ -90,20 +92,20 @@
}
printf("\n");
- MemoryRemote remote_memory(pid);
+ unwindstack::MemoryRemote remote_memory(pid);
for (size_t frame_num = 0; frame_num < 64; frame_num++) {
if (regs->pc() == 0) {
break;
}
- MapInfo* map_info = remote_maps.Find(regs->pc());
+ unwindstack::MapInfo* map_info = remote_maps.Find(regs->pc());
if (map_info == nullptr) {
printf("Failed to find map data for the pc\n");
break;
}
- Elf* elf = map_info->GetElf(pid, true);
+ unwindstack::Elf* elf = map_info->GetElf(pid, true);
- uint64_t rel_pc = regs->GetRelPc(elf, map_info);
+ uint64_t rel_pc = elf->GetRelPc(regs->pc(), map_info);
uint64_t adjusted_rel_pc = rel_pc;
// Don't need to adjust the first frame pc.
if (frame_num != 0) {