我一直在使用libzip来处理zip文件,并且我的代码基于rodrigo对这个问题的答案中找到的例子.这是他的代码,供快速参考:
#include <zip.h>
int main()
{
//Open the ZIP archive
int err = 0;
zip *z = zip_open("foo.zip", 0, &err);
//Search for the file of given name
const char *name = "file.txt";
struct zip_stat st;
zip_stat_init(&st);
zip_stat(z, name, 0, &st);
//Alloc memory for its uncompressed contents
char *contents = new char[st.size];
//Read the compressed file
zip_file *f = zip_fopen(z, "file.txt", 0);
zip_fread(f, contents, st.size);
zip_fclose(f);
//And close the archive
zip_close(z);
}
Run Code Online (Sandbox Code Playgroud)
我将随后从Valgrind得到的错误追溯到这个代码 - 当使用'zip_fopen()`打开压缩的"file.txt"时,它会抱怨未初始化的值.
==29256== Conditional jump or …Run Code Online (Sandbox Code Playgroud) 我正在使用stomp.py库通过网络获取 JSON 消息。我已经修改了他们在此处提供的简单示例,该示例使用回调来提供消息处理。
但是当我修改那个回调时我犯了一个简单的错误 - 例如,我在尝试解析我的 JSON 字符串时调用了 json.load() 而不是 json.loads() 。
class MyListener(object):
def on_message(self, headers, message):
data = json.load(message) ## Should be .loads() for a string!
Run Code Online (Sandbox Code Playgroud)
通常这会很好 - 它会出现 AttributeError 并且我会看到回溯。但在这种情况下,Python 打印:
找不到记录器“stomp.py”的处理程序
...没有回溯,没有崩溃,仅此而已。调试非常混乱,找出我做错了什么!我至少期待以下方面的正常追溯:
Traceback (most recent call last):
File "./ncl/stomp.py-3.1.3/stompJSONParser.py", line 32, in <module>
[etc etc ...]
Run Code Online (Sandbox Code Playgroud)
......而不是让整个听众感到厌烦。我猜是因为那发生在不同的线程上?
现在我已经发现它就像回调中的一种运行时错误我至少知道我在出错时做错了什么 - 但如果它只是为我犯的每个错误喷出那个错误而不是给我某种有用的消息,这使得编码有点困难。
这是什么原因造成的?我该怎么做才能获得常规的、更详细的回溯?