Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Fix DW_OP_addr to translate address into virtual address space
[simgrid.git] / testsuite / mc / dwarf.c
index eecba82..c935a12 100644 (file)
@@ -37,6 +37,43 @@ static dw_variable_t find_global_variable_by_name(mc_object_info_t info, const c
   return NULL;
 }
 
+static dw_frame_t find_function_by_name(mc_object_info_t info, const char* name) {
+  xbt_dict_cursor_t cursor = 0;
+  dw_frame_t subprogram;
+  char* key;
+  xbt_dict_foreach(info->subprograms, cursor, key, subprogram){
+    if(!strcmp(name, subprogram->name))
+      return subprogram;
+  }
+
+  return NULL;
+}
+
+static dw_variable_t find_local_variable(dw_frame_t frame, const char* argument_name) {
+  unsigned int cursor = 0;
+  dw_variable_t variable;
+  xbt_dynar_foreach(frame->variables, cursor, variable){
+    if(!strcmp(argument_name, variable->name))
+      return variable;
+  }
+
+  return NULL;
+}
+
+static void test_local_variable(mc_object_info_t info, const char* function, const char* variable, void* address, unw_cursor_t* cursor) {
+  dw_frame_t subprogram = find_function_by_name(info, function);
+  assert(subprogram);
+  // TODO, Lookup frame by IP and test against name instead
+
+  dw_variable_t var = find_local_variable(subprogram, variable);
+  assert(var);
+
+  void* frame_base = mc_find_frame_base(subprogram, info, cursor);
+  xbt_assert((void*)mc_dwarf_resolve_locations(&var->locations, info, cursor, frame_base, NULL) == address,
+    "Bad resolution of local variable %s of %s", variable, function);
+
+}
+
 static dw_variable_t test_global_variable(mc_object_info_t info, const char* name, void* address, long byte_size) {
   dw_variable_t variable = find_global_variable_by_name(info, name);
   xbt_assert(variable, "Global variable %s was not found", name);
@@ -51,7 +88,7 @@ static dw_variable_t test_global_variable(mc_object_info_t info, const char* nam
   return variable;
 }
 
-static dw_type_t find_type(mc_object_info_t info, const char* name, dw_type_t type) {
+static dw_type_t find_member(mc_object_info_t info, const char* name, dw_type_t type) {
   unsigned int cursor = 0;
   dw_type_t member;
   xbt_dynar_foreach(type->members, cursor, member){
@@ -63,6 +100,12 @@ static dw_type_t find_type(mc_object_info_t info, const char* name, dw_type_t ty
 
 int some_local_variable = 0;
 
+typedef struct foo {int i;} s_foo;
+
+static void test_type_by_name(s_foo my_foo) {
+  assert(xbt_dict_get_or_null(mc_binary_info->full_types_by_name, "struct foo"));
+}
+
 int main(int argc, char** argv) {
 
   // xbt_init(&argc, argv);
@@ -81,9 +124,19 @@ int main(int argc, char** argv) {
 
   var = test_global_variable(mc_binary_info, "test_some_struct", &test_some_struct, sizeof(test_some_struct));
   type = xbt_dict_get_or_null(mc_binary_info->types, var->type_origin);
-  assert(find_type(mc_binary_info, "first", type)->offset == 0);
-  assert(find_type(mc_binary_info, "second", type)->offset
+  assert(find_member(mc_binary_info, "first", type)->offset == 0);
+  assert(find_member(mc_binary_info, "second", type)->offset
       == ((const char*)&test_some_struct.second) - (const char*)&test_some_struct);
 
+  unw_context_t context;
+  unw_cursor_t cursor;
+  unw_getcontext(&context);
+  unw_init_local(&cursor, &context);
+
+  test_local_variable(mc_binary_info, "main", "argc", &argc, &cursor);
+
+  s_foo my_foo;
+  test_type_by_name(my_foo);
+
   _exit(0);
 }