简体   繁体   English

使用 GDB 调试 json_t 对象

[英]Debugging json_t object with GDB

I have a application in C programming which uses jansson library(json library written in C).我有一个 C 编程应用程序,它使用 jansson 库(用 C 编写的 json 库)。 I'm trying to view value of json_t object in gdb but it just prints我正在尝试在 gdb 中查看 json_t 对象的值,但它只是打印

(gdb) p jmsg
$20 = (json_t *) 0x69c350
(gdb) p *jmsg
$21 = {type = JSON_OBJECT, refcount = 1}

How is it possible to view the value of json_t in gdb.?如何在gdb中查看json_t的值?

When in GDB, you can make function calls directly.在 GDB 中,您可以直接进行函数调用。 Jansson library has a json_dumps(json_t *, int flags) API that returns a char* string of the json_t object. Jansson 库有一个 json_dumps(json_t *, int flags) API,它返回 json_t 对象的 char* 字符串。

So while in GDB, just simply do:因此,在 GDB 中,只需执行以下操作:

(gdb) call json_dumps(obj, 0)

GDB will then print the string output of your json object.然后 GDB 将打印 json 对象的字符串输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM