arm: Factor some repetition out of the ProcessInfo constructor.
authorGabe Black <gabeblack@google.com>
Thu, 25 Apr 2019 00:13:37 +0000 (17:13 -0700)
committerGabe Black <gabeblack@google.com>
Fri, 26 Apr 2019 00:56:51 +0000 (00:56 +0000)
Change-Id: I34f952d1097886704d37304478de125a915b2615
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/18371
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Anthony Gutierrez <anthony.gutierrez@amd.com>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Jason Lowe-Power <jason@lowepower.com>

src/arch/arm/stacktrace.cc

index 0033876a019bf69d8752911c65e9121ca2dbbd10..de577755489692cc500ada2ea42d7d4a19a325a7 100644 (file)
 namespace ArmISA
 {
 
-ProcessInfo::ProcessInfo(ThreadContext *_tc)
-    : tc(_tc)
+static int32_t
+readSymbol(ThreadContext *tc, const std::string name)
 {
-    Addr addr = 0;
-
     FSTranslatingPortProxy &vp = tc->getVirtProxy();
+    SymbolTable *symtab = tc->getSystemPtr()->kernelSymtab;
 
-    if (!tc->getSystemPtr()->kernelSymtab->findAddress(
-                "thread_info_size", addr)) {
-        panic("thread info not compiled into kernel\n");
-    }
-    thread_info_size = vp.readGtoH<int32_t>(addr);
-
-    if (!tc->getSystemPtr()->kernelSymtab->findAddress(
-                "task_struct_size", addr)) {
-        panic("thread info not compiled into kernel\n");
-    }
-    task_struct_size = vp.readGtoH<int32_t>(addr);
-
-    if (!tc->getSystemPtr()->kernelSymtab->findAddress(
-                "thread_info_task", addr)) {
+    Addr addr;
+    if (!symtab->findAddress(name, addr))
         panic("thread info not compiled into kernel\n");
-    }
-    task_off = vp.readGtoH<int32_t>(addr);
 
-    if (!tc->getSystemPtr()->kernelSymtab->findAddress(
-                "task_struct_pid", addr)) {
-        panic("thread info not compiled into kernel\n");
-    }
-    pid_off = vp.readGtoH<int32_t>(addr);
+    return vp.readGtoH<int32_t>(addr);
+}
 
-    if (!tc->getSystemPtr()->kernelSymtab->findAddress(
-                "task_struct_comm", addr)) {
-        panic("thread info not compiled into kernel\n");
-    }
-    name_off = vp.readGtoH<int32_t>(addr);
+ProcessInfo::ProcessInfo(ThreadContext *_tc) : tc(_tc)
+{
+    thread_info_size = readSymbol(tc, "thread_info_size");
+    task_struct_size = readSymbol(tc, "task_struct_size");
+    task_off = readSymbol(tc, "thread_info_task");
+    pid_off = readSymbol(tc, "task_struct_pid");
+    name_off = readSymbol(tc, "task_struct_comm");
 }
 
 Addr