llvm-project/lldb/source/Target
Walter Erquinigo ade59d5309 [trace] Dedup different source lines when dumping instructions + refactor
When dumping the traced instructions in a for loop, like this one

  4:  for (int a = 0; a < n; a++)
  5:    do something;

there might be multiple LineEntry objects for line 4, but with different address ranges. This was causing the dump command to dump something like this:

```
  a.out`main + 11 at main.cpp:4
    [1] 0x0000000000400518    movl   $0x0, -0x8(%rbp)
    [2] 0x000000000040051f    jmp    0x400529                  ; <+28> at main.cpp:4
  a.out`main + 28 at main.cpp:4
    [3] 0x0000000000400529    cmpl   $0x3, -0x8(%rbp)
    [4] 0x000000000040052d    jle    0x400521                  ; <+20> at main.cpp:5
```

which is confusing, as main.cpp:4 appears twice consecutively.

This diff fixes that issue by making the line entry comparison strictly about the line, column and file name. Before it was also comparing the address ranges, which we don't need because our output is strictly about what the user sees in the source.

Besides, I've noticed that the logic that traverses instructions and calculates symbols and disassemblies had too much coupling, and made my changes harder to implement, so I decided to decouple it. Now there are two methods for iterating over the instruction of a trace. The existing one does it on raw load addresses, but the one provides a SymbolContext and an InstructionSP, and does the calculations efficiently (not as efficient as possible for now though), so the caller doesn't need to care about these details. I think I'll be using that iterator to reconstruct the call stacks.

I was able to fix a test with this change.

Differential Revision: https://reviews.llvm.org/D100740
2021-05-04 19:40:52 -07:00
..
ABI.cpp Make the error condition in Value::ValueType explicit (NFC) 2021-02-12 16:12:31 -08:00
AssertFrameRecognizer.cpp The AssertRecognizer used the module from a frames SC without checking it was non-null. 2020-11-13 11:41:32 -08:00
CMakeLists.txt [trace][intel-pt] Implement trace start and trace stop 2021-03-30 17:31:37 -07:00
ExecutionContext.cpp [lldb][NFC] Fix all formatting errors in .cpp file headers 2020-01-24 08:52:55 +01:00
InstrumentationRuntime.cpp [lldb][NFC] Fix all formatting errors in .cpp file headers 2020-01-24 08:52:55 +01:00
InstrumentationRuntimeStopInfo.cpp [lldb][NFC] Fix all formatting errors in .cpp file headers 2020-01-24 08:52:55 +01:00
JITLoader.cpp [lldb][NFC] Fix all formatting errors in .cpp file headers 2020-01-24 08:52:55 +01:00
JITLoaderList.cpp [lldb][NFC] Fix all formatting errors in .cpp file headers 2020-01-24 08:52:55 +01:00
Language.cpp [lldb/DataFormatters] Delete GetStringPrinterEscapingHelper 2020-05-04 14:06:55 -07:00
LanguageRuntime.cpp Add setting to disable LanguageRuntime UnwindPlans 2021-04-08 13:28:59 -07:00
Memory.cpp [LLDB] Fix AddressSanitizer failure in MemoryCache 2020-02-27 11:17:10 -08:00
MemoryHistory.cpp [lldb][NFC] Fix all formatting errors in .cpp file headers 2020-01-24 08:52:55 +01:00
MemoryRegionInfo.cpp [lldb][AArch64/Linux] Show memory tagged memory regions 2020-11-20 11:21:59 +00:00
ModuleCache.cpp [lldb] Use std::make_unique<> (NFC) 2020-06-24 17:48:40 -07:00
OperatingSystem.cpp [lldb] Delete copy operations on PluginInterface class 2020-10-09 10:37:09 +02:00
PathMappingList.cpp [lldb][NFC] Fix all formatting errors in .cpp file headers 2020-01-24 08:52:55 +01:00
Platform.cpp [lldb] "target create" shouldn't save target if the command failed 2020-12-12 16:40:58 +03:00
Process.cpp [lldb] [gdb-remote server] Introduce new stop reasons for fork and vfork 2021-04-24 11:08:33 +02:00
ProcessTrace.cpp [trace][intel-pt] Implement trace start and trace stop 2021-03-30 17:31:37 -07:00
Queue.cpp [lldb][NFC] Fix all formatting errors in .cpp file headers 2020-01-24 08:52:55 +01:00
QueueItem.cpp [lldb][NFC] Fix all formatting errors in .cpp file headers 2020-01-24 08:52:55 +01:00
QueueList.cpp [lldb][NFC] Fix all formatting errors in .cpp file headers 2020-01-24 08:52:55 +01:00
RegisterContext.cpp LanguageRuntime for 0th frame unwind, simplify getting pc-for-symbolication 2021-03-03 19:29:40 -08:00
RegisterContextUnwind.cpp [lldb] Implement ABI::Fix{Code,Data}Address for AArch64 2021-04-16 13:49:38 -07:00
RegisterNumber.cpp [lldb][NFC] Fix all formatting errors in .cpp file headers 2020-01-24 08:52:55 +01:00
RemoteAwarePlatform.cpp [lldb] Move PlatformPOSIX::ConnectToWaitingProcesses to RemoteAwarePlatform 2021-03-14 22:43:52 +01:00
SectionLoadHistory.cpp [lldb][NFC] Fix all formatting errors in .cpp file headers 2020-01-24 08:52:55 +01:00
SectionLoadList.cpp [lldb] Switch Section-dumping code to raw_ostream 2020-05-14 11:59:18 +02:00
StackFrame.cpp Target::ReadMemory read from read-only binary file Section, not memory 2021-04-16 16:13:07 -07:00
StackFrameList.cpp [lldb] [gdb-remote server] Introduce new stop reasons for fork and vfork 2021-04-24 11:08:33 +02:00
StackFrameRecognizer.cpp [lldb] Make deleting frame recognizers actually work 2020-07-23 17:43:37 +02:00
StackID.cpp [lldb][NFC] Fix all formatting errors in .cpp file headers 2020-01-24 08:52:55 +01:00
StopInfo.cpp [trace][intel-pt] Implement trace start and trace stop 2021-03-30 17:31:37 -07:00
StructuredDataPlugin.cpp [lldb][NFC] Fix all formatting errors in .cpp file headers 2020-01-24 08:52:55 +01:00
SystemRuntime.cpp [lldb] Have LanguageRuntime and SystemRuntime share a base class (NFC) 2020-07-24 16:28:34 -07:00
Target.cpp [lldb] Refactor argument group by SourceLocationSpec (NFCI) 2021-05-04 23:04:31 +00:00
TargetList.cpp [lldb] Abstract scoped timer logic behind LLDB_SCOPED_TIMER (NFC) 2020-12-22 09:10:27 -08:00
TargetProperties.td [lldb] Add code and data address mask to Process 2021-04-16 12:30:54 -07:00
Thread.cpp [lldb] [gdb-remote server] Introduce new stop reasons for fork and vfork 2021-04-24 11:08:33 +02:00
ThreadCollection.cpp [lldb][NFC] Fix all formatting errors in .cpp file headers 2020-01-24 08:52:55 +01:00
ThreadList.cpp Allow the ThreadPlanStackMap to hold the thread plans for threads 2020-04-03 14:56:28 -07:00
ThreadPlan.cpp [lldb] Rename {stop,run}_vote to report_{stop,run}_vote 2021-02-19 13:04:53 -08:00
ThreadPlanBase.cpp [lldb] Rename {stop,run}_vote to report_{stop,run}_vote 2021-02-19 13:04:53 -08:00
ThreadPlanCallFunction.cpp [lldb] Minor refinements to ThreadPlan::RestoreThreadState (NFC) 2021-02-15 17:57:13 -08:00
ThreadPlanCallFunctionUsingABI.cpp Make ThreadPlans use TID and Process, rather than Thread *. 2020-04-03 14:56:28 -07:00
ThreadPlanCallOnFunctionExit.cpp [lldb][NFC] Fix all formatting errors in .cpp file headers 2020-01-24 08:52:55 +01:00
ThreadPlanCallUserExpression.cpp Make ThreadPlans use TID and Process, rather than Thread *. 2020-04-03 14:56:28 -07:00
ThreadPlanPython.cpp Add a setting to force stepping to always run all threads. 2020-08-07 14:47:31 -07:00
ThreadPlanRunToAddress.cpp Make ThreadPlans use TID and Process, rather than Thread *. 2020-04-03 14:56:28 -07:00
ThreadPlanShouldStopHere.cpp [lldb][NFC] Fix all formatting errors in .cpp file headers 2020-01-24 08:52:55 +01:00
ThreadPlanStack.cpp [lldb] Rename QueueFundamentalPlan to QueueBasePlan (NFC) 2021-03-04 21:46:49 -08:00
ThreadPlanStepInRange.cpp [lldb] Add step target to ThreadPlanStepInRange constructor 2021-02-11 14:57:20 -08:00
ThreadPlanStepInstruction.cpp [lldb] Rename {stop,run}_vote to report_{stop,run}_vote 2021-02-19 13:04:53 -08:00
ThreadPlanStepOut.cpp [lldb] Rename {stop,run}_vote to report_{stop,run}_vote 2021-02-19 13:04:53 -08:00
ThreadPlanStepOverBreakpoint.cpp [lldb] Remove duplicated ThreadPlanStepOverBreakpoint comment 2021-03-08 22:34:56 -08:00
ThreadPlanStepOverRange.cpp Make ThreadPlans use TID and Process, rather than Thread *. 2020-04-03 14:56:28 -07:00
ThreadPlanStepRange.cpp Target::ReadMemory read from read-only binary file Section, not memory 2021-04-16 16:13:07 -07:00
ThreadPlanStepThrough.cpp [lldb] Remove very old misleading comment (NFC) 2021-02-15 18:14:57 -08:00
ThreadPlanStepUntil.cpp Make ThreadPlans use TID and Process, rather than Thread *. 2020-04-03 14:56:28 -07:00
ThreadPlanTracer.cpp [lldb] Remove unused ThreadPlan tracer utilities (NFC) 2021-02-15 17:59:25 -08:00
ThreadPostMortemTrace.cpp [trace][intel-pt] Implement trace start and trace stop 2021-03-30 17:31:37 -07:00
ThreadSpec.cpp [lldb][NFC] Fix all formatting errors in .cpp file headers 2020-01-24 08:52:55 +01:00
Trace.cpp [trace] Dedup different source lines when dumping instructions + refactor 2021-05-04 19:40:52 -07:00
TraceSessionFileParser.cpp [trace][intel-pt] Implement trace start and trace stop 2021-03-30 17:31:37 -07:00
UnixSignals.cpp [lldb] Format remaining signal table (NFC) 2020-10-08 21:51:41 -07:00
UnwindAssembly.cpp [lldb] Delete copy operations on PluginInterface class 2020-10-09 10:37:09 +02:00
UnwindLLDB.cpp LanguageRuntime for 0th frame unwind, simplify getting pc-for-symbolication 2021-03-03 19:29:40 -08:00