Просмотр исходного кода

aot debug: Try to use a bit more appropriate file names (#3000)

When the original wasm contains multiple compilation units, the current
logic uses the first one for everything. This commit tries to use a bit more
appropriate ones.
YAMAMOTO Takashi 2 лет назад
Родитель
Сommit
837b9904f5
1 измененных файлов с 20 добавлено и 4 удалено
  1. 20 4
      core/iwasm/compilation/debug/dwarf_extractor.cpp

+ 20 - 4
core/iwasm/compilation/debug/dwarf_extractor.cpp

@@ -133,9 +133,10 @@ dwarf_gen_file_info(const AOTCompContext *comp_ctx)
         file_name = filespec.GetFilename();
         dir_name = filespec.GetDirectory();
         if (file_name || dir_name) {
-            file_info = LLVMDIBuilderCreateFile(comp_ctx->debug_builder,
-                                                file_name, strlen(file_name),
-                                                dir_name, strlen(dir_name));
+            file_info = LLVMDIBuilderCreateFile(
+                comp_ctx->debug_builder, file_name,
+                file_name ? strlen(file_name) : 0, dir_name,
+                dir_name ? strlen(dir_name) : 0);
         }
     }
     return file_info;
@@ -298,7 +299,7 @@ lldb_function_to_function_dbi(const AOTCompContext *comp_ctx,
         return NULL;
 
     LLVMDIBuilderRef DIB = comp_ctx->debug_builder;
-    LLVMMetadataRef File = comp_ctx->debug_file;
+    LLVMMetadataRef File = comp_ctx->debug_file; /* a fallback */
 
     LLVMMetadataRef ParamTypes[num_function_args + 1];
 
@@ -315,6 +316,21 @@ lldb_function_to_function_dbi(const AOTCompContext *comp_ctx,
         }
     }
 
+    auto compile_unit = sc.GetCompileUnit();
+    auto file_spec = compile_unit.GetFileSpec();
+    const char *file_name = file_spec.GetFilename();
+    const char *dir_name = file_spec.GetDirectory();
+    LLVMMetadataRef file_info = NULL;
+    if (file_name || dir_name) {
+        file_info =
+            LLVMDIBuilderCreateFile(comp_ctx->debug_builder, file_name,
+                                    file_name ? strlen(file_name) : 0, dir_name,
+                                    dir_name ? strlen(dir_name) : 0);
+    }
+    if (file_info) {
+        File = file_info;
+    }
+
     LLVMMetadataRef FunctionTy = LLVMDIBuilderCreateSubroutineType(
         DIB, File, ParamTypes, num_function_args + 1, LLVMDIFlagZero);