[PATCH] D147112: [symbolizer] Factor out conversion DILineInfo->JSON. NFC

Serge Pavlov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 28 22:28:05 PDT 2023


sepavloff created this revision.
sepavloff added reviewers: jhenderson, mysterymath, MaskRay, dblaikie, ikudrin, dvyukov.
Herald added a subscriber: hiraditya.
Herald added a project: All.
sepavloff requested review of this revision.
Herald added a project: LLVM.

Move the conversion of DILineInfo to JSON into a separate function, so
it can be used in other places too.

This is a prerequisite patch for implementation of symbol+offset lookup.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147112

Files:
  llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp


Index: llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
===================================================================
--- llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
+++ llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
@@ -293,6 +293,24 @@
   return Json;
 }
 
+static json::Object toJSON(const DILineInfo &LineInfo) {
+  return json::Object(
+      {{"FunctionName", LineInfo.FunctionName != DILineInfo::BadString
+                            ? LineInfo.FunctionName
+                            : ""},
+       {"StartFileName", LineInfo.StartFileName != DILineInfo::BadString
+                             ? LineInfo.StartFileName
+                             : ""},
+       {"StartLine", LineInfo.StartLine},
+       {"StartAddress",
+        LineInfo.StartAddress ? toHex(*LineInfo.StartAddress) : ""},
+       {"FileName",
+        LineInfo.FileName != DILineInfo::BadString ? LineInfo.FileName : ""},
+       {"Line", LineInfo.Line},
+       {"Column", LineInfo.Column},
+       {"Discriminator", LineInfo.Discriminator}});
+}
+
 void JSONPrinter::print(const Request &Request, const DILineInfo &Info) {
   DIInliningInfo InliningInfo;
   InliningInfo.addFrame(Info);
@@ -303,21 +321,7 @@
   json::Array Array;
   for (uint32_t I = 0, N = Info.getNumberOfFrames(); I < N; ++I) {
     const DILineInfo &LineInfo = Info.getFrame(I);
-    json::Object Object(
-        {{"FunctionName", LineInfo.FunctionName != DILineInfo::BadString
-                              ? LineInfo.FunctionName
-                              : ""},
-         {"StartFileName", LineInfo.StartFileName != DILineInfo::BadString
-                               ? LineInfo.StartFileName
-                               : ""},
-         {"StartLine", LineInfo.StartLine},
-         {"StartAddress",
-          LineInfo.StartAddress ? toHex(*LineInfo.StartAddress) : ""},
-         {"FileName",
-          LineInfo.FileName != DILineInfo::BadString ? LineInfo.FileName : ""},
-         {"Line", LineInfo.Line},
-         {"Column", LineInfo.Column},
-         {"Discriminator", LineInfo.Discriminator}});
+    json::Object Object = toJSON(LineInfo);
     SourceCode SourceCode(LineInfo.FileName, LineInfo.Line,
                           Config.SourceContextLines, LineInfo.Source);
     std::string FormattedSource;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147112.509215.patch
Type: text/x-patch
Size: 2285 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230329/26d99f93/attachment.bin>


More information about the llvm-commits mailing list