'Is it possible LLDB load scripts conditionally?
The problem description
I want to print int8x8_t type variable for different target architectures: ARM NEON(real device via remote debugging), and ARM NEON Simulation(on PC).
When without format print customization, ARM NEON platforms works as expected, while simulation gives messy output.
When with format print customization, simulation gives expected output, while ARM NEON platform gives all 0 values.
Q1: Is it possible to load lldb config script files conditionally, according to the target is arm/aarch64 or x86/x64?
Q2: Is it possible in the format print customization function, print for both platforms?
The detail code and lldb execution output:
The int8x8_t type variable:
#if __ARM_NEON
#include <arm_neon.h>
#else
// the simulation
#include <stdint.h>
typedef struct int8x8_t
{
int8_t val[8];
} int8x8_t;
void vst1_s8(int8_t* ptr, int8x8_t& vd)
{
for (int i = 0; i < 8; i++)
ptr[i] = vd.val[i];
}
// end of the simulation
#endif
int main()
{
int8x8_t vd = {-128, -3, -5, 7, 2, 4, 6, 127};
int8_t ptr[8];
vst1_s8(ptr, vd);
printf("Done\n"); // set a breakpoint in this line, and call `p vd` in lldb command window
return 0;
}
The output, without lldb print format customization
The ARM platform support printing it naturally:
-> p vd
(int8x8_t) $1 = (-128, -3, -5, 7, 2, 4, 6, 127)
on PC with the simulation implementation of ARM NEON, it gives some messy:
vd
(int8x8_t) $0 = (val = "\x80\xfd\xfb\a\U00000002\U00000004\U00000006\U0000007f")
The output, with lldb print format customization
With some customization, the PC output becomes same as the previously ARM output:
# ~/.lldbcfg/my_print.py
def print_int8x8_t(valobj, internal_dict):
arch = get_arch()
val = valobj.GetChildMemberWithName("val")
res = '('
for i in range(8):
if(i>0): res += ', '
res += str(val.GetChildAtIndex(i).GetValueAsSigned(0))
res += ')'
return res
def __lldb_init_module(debugger, internal_dict):
debugger.HandleCommand('type summary add -P int8x8_t -F {:s}.print_int8x8_t'.format(__name__))
~/.lldb
command script import ~/.lldbcfg/my_print.py
ARM platform:
-> p vd
(int8x8_t) $0 = (0, 0, 0, 0, 0, 0, 0, 0)
Solution 1:[1]
The "how to load scripts conditionally" part is covered by:
How to import Facebook's Chisel fbchisellldb.py depend on the chip type(M1/Intel)?
However, for this formatter you really care about the target architecture not the host architecture. So switching which formatter you feed to the debugger when you start up will only work if your target architecture is always the same and known at startup.
For more complex remote scenarios, switching on the target architecture in the formatter is actually simpler. That allows the data formatter you add when you start up (and don't yet know the target architecture) to make the right choice at the time the formatter is run.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jim Ingham |
