Qt、Linux 以及其他:调试 Qt WebAssembly
Qt, Linux and everything: Debugging Qt WebAssembly

原始链接: http://qtandeverything.blogspot.com/2025/12/debugging-qt-webassembly-dwarf.html

调试 Qt WebAssembly 应用程序可能具有挑战性,但使用 DWARF 符号可以简化此过程。最简单的方法是在 CMake 中使用 `-g`(或 `-g3`)参数构建(设置 `CMAKE_BUILD_TYPE=Debug`),这会将调试信息直接嵌入到 WASM 二进制文件中。 但是,此方法*仅*在 Chrome 浏览器中安装了“C/C++ DevTools Support (DWARF)”扩展程序后才能工作。安装并启用该扩展程序后,重新加载您的 Web 应用程序将解析符号——这个过程可能需要时间,特别是对于 Qt 应用程序。 与源映射不同,DWARF 不需要指向源目录的符号链接,因为文件路径已嵌入其中。这允许在 Chrome 调试器中直接设置断点和单步执行代码,并像调试本机应用程序一样显示变量名称和值。其他调试方法,如源映射,将在未来的文章中介绍,以供 Safari 和 Firefox 等浏览器使用。

黑客新闻 新 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 Qt、Linux 和其他:调试 Qt WebAssembly (qtandeverything.blogspot.com) 11 分,由 speckx 发表于 41 分钟前 | 隐藏 | 过去 | 收藏 | 讨论 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文

 

One of the most tedious tasks a developer will do is debugging a nagging bug. It's worse when it's a web app, and even worse when its a webassembly web app.


The easiest way to debug Qt Webassembly is by configuring using the -g argument, or CMAKE_BUILD_TYPE=Debug . Emscripten embeds DWARF symbols in the wasm binaries. 

NOTE: Debugging wasm files with DWARF works only in the Chrome browser with the help of a browser extension. 

C/C++ DevTools Support (DWARF) browser extension. If you are using Safari or Firefox, or do not want to or cannot install a browser extension, you will need to generate source maps, which I will look at in my next blog post. 

DWARF debugging

You need to also enable DWARF in the browser developer tools settings, but you do not need symlinks to the source directories, as you would need to using source maps, as the binaries are embedded with the full directory path. Like magic!

 Emscripten embeds DWARF symbols into the binaries built with -g by default, so re-building Qt or your application in debug mode is all you need to do.

Qt builds debug libraries by default using the optimized argument -g2, which produces less debugging info, but results in faster link times. To preserve debug symbols you need to build Qt debug using the -g or -g3 argument. Both of these do the same thing.

Using DWARF debugger

Open Chome with the extention mentioned before installed, and open the console tools. Navigate to the Qt for WebAssembly web application you need to debug. Once it opens, it may take a few seconds for all the symbols and files to get parsed. If you are debugging into Qt, this will take quite a few seconds - just keep waiting. 

The javascript console will soon contain file source file paths and sources. You can find your file to debug, and set breakpoints. Just reload the page and once it hits a breakpoint, it will stop execution and highlight the current line in the source view.  It also will show variable names and values.


You can then step though your code as you would debugging a desktop application.
联系我们 contact @ memedata.com