如何为qtcreator编写调试助手? [英] How to write a debugging helper for qtcreator?

查看:164
本文介绍了如何为qtcreator编写调试助手?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用带有gdb的glm :: vec3类调试我的C ++程序时,使用以下向量类非常麻烦:



我已阅读

解决方案

简短的答案:一个最小示例



以下是调试助手的最小示例:



C ++代码:

  class Foo 
{
};

int main(int,char **)
{
Foo foo;

(void)foo;

返回0;
}

调试助手:



从转储器导入中的

  * 

def qdump__Foo(d,value):
d.putNumChild(0)
d.putValue (是的,Foo的作品是:))

结果:





说明



您将 put putValue 混合在一起。要引用您提供的



说明



vec3不显示的原因是, glm :: vec3 不是类型,而只是typedef。 glm :: tvec3是您要查找的类型:

  typedef tvec3< float,highp> highp_vec3; 
// [...]
typedef highp_vec3 vec3;

因此,通过替换 def qdump__glm__vec3(d,value): def qdump__glm__tvec3(d,value):,gdb将能够找到您的函数。



要访问成员本身,例如成员 x ,请使用 value [ x] 。这样,您可以使用 d.putValue 获得令人愉悦的输出。

为了以可扩展的方式显示成员自身,我使用了示例您提供的链接


When debugging my C++ program using the glm::vec3 class with gdb, the vector classes are quite cumbersome to work with:

I've read in the manual, that it's possible to write debug helpers.
I've managed to get qtcreator to load the file (the debugger exits immediately with an error, if my python file has a syntax error).

How can I write a minimalistic debugging helper?

What I've already tried:

Here's the C++ code

#include <glm/glm.hpp>

class Foo
{
};

int main(int, char**)
{
  glm::vec3 vec3(42, 64, 256);
  Foo foo;

  (void)vec3;
  (void)foo;

  return 0;
}

This is my debugging helper:

from dumper import *

def qdump__glm__vec3(d, value):
    d.put("Yay, vec3 works :)")

def qdump__Foo(d, value):
    d.put("Yay, Foo works :)")

The vec3 code seems not to have any visible effect. For foo, it seems to do something, but instead of printing Yay, Foo works :) , qtcreator just shows <not accessible>. See the following screenshot:

解决方案

The short Answer: A Minimum example

Here's a minimum example for a debug helper:

C++ code:

class Foo
{
};

int main(int, char**)
{
  Foo foo;

  (void)foo;

  return 0;
}

The debug-helper:

from dumper import *

def qdump__Foo(d, value):
    d.putNumChild(0)
    d.putValue("Yay, Foo works :)")

The result:

Explanation

You've mixed up put and putValue. To quote from the link you've provided:

put(self, value) - Low level function to directly append to the output string. That is also the fastest way to append output.

put is a low level function and requires a very specific formating and thus may not be the optimal starting point for a minimum example.
Use instead putValue, this function can be used to print the value of a variable.

The short Answer for glm::vec3

Here's the working example for glm::vec3:

C++ code:

#include <glm/glm.hpp>

int main(int, char**)
{
  glm::vec3 vec3(42, 64, 256);

  (void)vec3;

  return 0;
}

The debug-helper:

from dumper import *

def qdump__glm__tvec3(d, value):
    d.putValue("[{0}, {1}, {2}]".format(value["x"], value["y"], value["z"]))
    d.putNumChild(3)
    if d.isExpanded():
        with Children(d):
            d.putSubItem("x", value["x"])
            d.putSubItem("y", value["y"])
            d.putSubItem("z", value["z"])

The result:

And to match your first screenshot for debugging a ray:

Explanation

The reason, vec3 doesn't show up is, that glm::vec3 is not the type, but just a typedef. glm::tvec3 is the type you are looking for:

typedef tvec3<float, highp>     highp_vec3;
// [...]
typedef highp_vec3          vec3;

So by replacing def qdump__glm__vec3(d, value): with def qdump__glm__tvec3(d, value):, gdb will be able to find your function.

To access the members themselves, for example the member x, use value["x"]. This way you can use d.putValue for a pleasing output.
For showing the members themselves in an expandable way, I've used the example from the link you've provided.

这篇关于如何为qtcreator编写调试助手?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆