For example I have a simple substring class and a simple array. When I'm debugging it's a headache because I need many clicks just to get some kind of sensible information. Is there a way I can markup my source of have some kind of config that says when I print the variable a I actually mean
p *a.start@(a.end-a.start)
When I exam array I'd like it to show the variable in the style above (p *arr.array@arr.pos
is a mess)
Current GDB output
$ gdb ./a.out
(gdb) br a.cpp:38
Breakpoint 1 at 0x128f: file a.cpp, line 38.
(gdb) r
(gdb) p a
$1 = {start = 0x555555556004 "My test string that has two parts", end = 0x555555556012 " that has two parts"}
(gdb)
My Source compiled with g++ -g a.cpp
#include <cstdio>
struct MyString
{
const char *start, *end;
int size() { return end-start; }
};
template<class T>
struct MyArray
{
int pos;
T array[10];
MyArray() : pos(0) {}
void push(T val) {
if (pos >= 10)
return;
array[pos++] = val;
}
};
struct MoreComplex
{
int val;
MyString substring;
};
int main() {
const char* str = "My test string that has two parts";
MyString a{str, str+14};
MyString b{str+20, str+27};
MoreComplex c{5, b};
MyArray<MyString> arr;
arr.push(a);
arr.push(b);
MyArray<MoreComplex*> arr2;
arr2.push(&c);
puts("Breakpoint here");
return 0;
}