Show Array's Content in a Range in Qt Debugger

2019-07-16 10:20发布

问题:

I'm using QT Creator debugger. When I try to debug a large array (i.e. 1000,000 elements), it hangs for trying to retrieve the whole array's values, though I'm trying to see the first few elements only. In KDevelop the debugger shows the first 5 elements only, then I press click to show another 5 elements and so on.

Is it possible to do the same in QT Creator?

回答1:

The answer depends on the debugging backend you use, and the version of Qt Creator.

With GDB as debugging backend you can use 'Add New Expression Evaluator' form the the 'Locals and Expression' view's context menu, and enter '{Type[100]}a' to see the items a[0] through a[99] of an array defined as 'Type a[100000];'.

In Qt Creator 3.2 the simpler 'a[0..100]' works as expression, too, with both GDB and LLDB as debugging backend.



回答2:

It also works if you right click on the array variable in the Locals and Expressions pane and select "Add expression evaluator for [array variable]". Then the watched variable will show up in a divided pane. You should double click on the variable name, add a * before and a @qty after. Eg.: if the array variable is called myArray and you need to see the first 10 elements, then it should look like this: *myArray@10.