[lldb][trace] Fix some minor bugs in the call tree
authorWalter Erquinigo <wallace@fb.com>
Wed, 19 Oct 2022 07:18:01 +0000 (00:18 -0700)
committerWalter Erquinigo <wallace@fb.com>
Wed, 19 Oct 2022 07:44:48 +0000 (00:44 -0700)
- We weren't truncating the output files
- We weren't considering the case in which we couldn't disassembly an
instruction.

lldb/source/Commands/CommandObjectThread.cpp
lldb/source/Target/TraceDumper.cpp

index 414acfb..bfe8504 100644 (file)
@@ -2199,7 +2199,8 @@ protected:
     llvm::Optional<StreamFile> out_file;
     if (m_options.m_output_file) {
       out_file.emplace(m_options.m_output_file->GetPath().c_str(),
-                       File::eOpenOptionWriteOnly | File::eOpenOptionCanCreate);
+                       File::eOpenOptionWriteOnly | File::eOpenOptionCanCreate |
+                           File::eOpenOptionTruncate);
     }
 
     m_options.m_dumper_options.forwards = true;
@@ -2395,7 +2396,8 @@ protected:
     llvm::Optional<StreamFile> out_file;
     if (m_options.m_output_file) {
       out_file.emplace(m_options.m_output_file->GetPath().c_str(),
-                       File::eOpenOptionWriteOnly | File::eOpenOptionCanCreate);
+                       File::eOpenOptionWriteOnly | File::eOpenOptionCanCreate |
+                           File::eOpenOptionTruncate);
     }
 
     if (m_options.m_continue && !m_last_id) {
index 7a5214d..268dc03 100644 (file)
@@ -799,9 +799,14 @@ static TraceDumper::FunctionCall &AppendInstructionToFunctionCallForest(
   }
   // Now we are in a different symbol. Let's see if this is a return or a
   // call
-  switch (last_function_call->GetLastTracedSegment()
-              .GetLastInstructionSymbolInfo()
-              .instruction->GetControlFlowKind(&exe_ctx)) {
+  const InstructionSP &insn = last_function_call->GetLastTracedSegment()
+                                  .GetLastInstructionSymbolInfo()
+                                  .instruction;
+  InstructionControlFlowKind insn_kind =
+      insn ? insn->GetControlFlowKind(&exe_ctx)
+           : eInstructionControlFlowKindOther;
+
+  switch (insn_kind) {
   case lldb::eInstructionControlFlowKindCall:
   case lldb::eInstructionControlFlowKindFarCall: {
     // This is a regular call