[Lldb-commits] [lldb] ae376fe - Modify all register values whose byte size matches the address size to be formatter as eFormatAddressInfo.
Greg Clayton via lldb-commits
lldb-commits at lists.llvm.org
Mon Aug 22 14:48:28 PDT 2022
Author: Greg Clayton
Date: 2022-08-22T14:48:16-07:00
New Revision: ae376feb0b1922294884257811b9659eed83e1e1
URL: https://github.com/llvm/llvm-project/commit/ae376feb0b1922294884257811b9659eed83e1e1
DIFF: https://github.com/llvm/llvm-project/commit/ae376feb0b1922294884257811b9659eed83e1e1.diff
LOG: Modify all register values whose byte size matches the address size to be formatter as eFormatAddressInfo.
This allows users to see similar output to what the "register read" command emits in LLDB's command line.
Added a test to verify that the PC has the correct value with contains a pointer followed by the module + function name and the source line info. Something like:
0x0000000100000a64 a.out`main + 132 at main.cpp:17:11
Differential Revision: https://reviews.llvm.org/D129528
Added:
Modified:
lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py
lldb/tools/lldb-vscode/lldb-vscode.cpp
Removed:
################################################################################
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
index 8a871732f7a61..0996d8696cd25 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
@@ -447,6 +447,10 @@ def get_local_variables(self, frameIndex=0, threadId=None):
return self.get_scope_variables('Locals', frameIndex=frameIndex,
threadId=threadId)
+ def get_registers(self, frameIndex=0, threadId=None):
+ return self.get_scope_variables('Registers', frameIndex=frameIndex,
+ threadId=threadId)
+
def get_local_variable(self, name, frameIndex=0, threadId=None):
locals = self.get_local_variables(frameIndex=frameIndex,
threadId=threadId)
diff --git a/lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py b/lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py
index b4ed393290c3d..e4cb103010fde 100644
--- a/lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py
+++ b/lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py
@@ -459,3 +459,52 @@ def test_indexedVariables(self):
"pt": {"missing": ["indexedVariables"]},
}
self.verify_variables(verify_locals, locals)
+
+ @skipIfWindows
+ @skipIfRemote
+ def test_registers(self):
+ '''
+ Test that registers whose byte size is the size of a pointer on
+ the current system get formatted as lldb::eFormatAddressInfo. This
+ will show the pointer value followed by a description of the address
+ itself. To test this we attempt to find the PC value in the general
+ purpose registers, and since we will be stopped in main.cpp, verify
+ that the value for the PC starts with a pointer and is followed by
+ a description that contains main.cpp.
+ '''
+ program = self.getBuildArtifact("a.out")
+ self.build_and_launch(program)
+ source = "main.cpp"
+ breakpoint1_line = line_number(source, "// breakpoint 1")
+ lines = [breakpoint1_line]
+ # Set breakpoint in the thread function so we can step the threads
+ breakpoint_ids = self.set_source_breakpoints(source, lines)
+ self.assertEqual(
+ len(breakpoint_ids), len(lines), "expect correct number of breakpoints"
+ )
+ self.continue_to_breakpoints(breakpoint_ids)
+
+
+ pc_name = None
+ arch = self.getArchitecture()
+ if arch == 'x86_64':
+ pc_name = 'rip'
+ elif arch == 'x86':
+ pc_name = 'rip'
+ elif arch.startswith('arm'):
+ pc_name = 'pc'
+
+ if pc_name is None:
+ return
+ # Verify locals
+ reg_sets = self.vscode.get_registers()
+ for reg_set in reg_sets:
+ if reg_set['name'] == 'General Purpose Registers':
+ varRef = reg_set['variablesReference']
+ regs = self.vscode.request_variables(varRef)['body']['variables']
+ for reg in regs:
+ if reg['name'] == pc_name:
+ value = reg['value']
+ self.assertTrue(value.startswith('0x'))
+ self.assertTrue('a.out`main + ' in value)
+ self.assertTrue('at main.cpp:' in value)
diff --git a/lldb/tools/lldb-vscode/lldb-vscode.cpp b/lldb/tools/lldb-vscode/lldb-vscode.cpp
index 6c7118890f2f7..22ff84f42921b 100644
--- a/lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ b/lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -2933,6 +2933,25 @@ void request_variables(const llvm::json::Object &request) {
int64_t start_idx = 0;
int64_t num_children = 0;
+ if (variablesReference == VARREF_REGS) {
+ // Change the default format of any pointer sized registers in the first
+ // register set to be the lldb::eFormatAddressInfo so we show the pointer
+ // and resolve what the pointer resolves to. Only change the format if the
+ // format was set to the default format or if it was hex as some registers
+ // have formats set for them.
+ const uint32_t addr_size = g_vsc.target.GetProcess().GetAddressByteSize();
+ lldb::SBValue reg_set = g_vsc.variables.registers.GetValueAtIndex(0);
+ const uint32_t num_regs = reg_set.GetNumChildren();
+ for (uint32_t reg_idx=0; reg_idx<num_regs; ++reg_idx) {
+ lldb::SBValue reg = reg_set.GetChildAtIndex(reg_idx);
+ const lldb::Format format = reg.GetFormat();
+ if (format == lldb::eFormatDefault || format == lldb::eFormatHex) {
+ if (reg.GetByteSize() == addr_size)
+ reg.SetFormat(lldb::eFormatAddressInfo);
+ }
+ }
+ }
+
num_children = top_scope->GetSize();
const int64_t end_idx = start_idx + ((count == 0) ? num_children : count);
More information about the lldb-commits
mailing list