如何在gdb中打印wstring

发布于 2024-07-06 19:12:29 字数 27 浏览 6 评论 0原文

如何在 gdb 中打印 wstring?

How can I print wstring in gdb?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

世界等同你 2024-07-13 19:12:30

我做了一些研究,这是 gdb PR716 PR1998PR2264。 显然,这是一项经常要求的功能,但尚未实现。

I did some research, and this is gdb PR716, PR1998, PR2264. Apparently this is an often-requested feature that is not yet implemented.

月亮是我掰弯的 2024-07-13 19:12:29

call printf %ls 仅有时有效,但要使其在 gdb 6.3 中完全正常工作,您需要所示的 void 转换和换行 \n这里:

call (void)printf("\"%ls\"\n",str.c_str())

这是一个更可靠的命令,您可以将其放入 .gdbinit 中,该命令也显示非 ASCII 代码点:

define wc_print
echo "
set $c = (wchar_t*)$arg0
while ( *$c )
  if ( *$c > 0x7f )
    printf "[%x]", *$c
  else
    printf "%c", *$c
  end
  set $c++
end
echo "\n
end

只需输入 wcwc_print 的缩写),并带有 <代码>std::wstring 或wchar_t*

更多详细信息,请访问 http://www.firstobject.com/wchar_t-gdb.htm

call printf %ls only works sometimes, but to get it to work at all in gdb 6.3 you need the void cast and linefeed \n shown here:

call (void)printf("\"%ls\"\n",str.c_str())

here is a more reliable command you can put in your .gdbinit that also shows non-ASCII code points:

define wc_print
echo "
set $c = (wchar_t*)$arg0
while ( *$c )
  if ( *$c > 0x7f )
    printf "[%x]", *$c
  else
    printf "%c", *$c
  end
  set $c++
end
echo "\n
end

just enter wc (short for wc_print) with either a std::wstring or wchar_t*.

More detail at http://www.firstobject.com/wchar_t-gdb.htm

我为君王 2024-07-13 19:12:29

假设您有一个 std::wstring str。 以下内容应该在 gdb 中工作:(

call printf("%ls", str._M_data())

printf 中的 -l 选项使其成为一个长字符串,我相信您需要“call”语句,因为普通的 gdb printf 不喜欢该选项。)

Suppose you've got a std::wstring str. The following should work in gdb:

call printf("%ls", str._M_data())

(The -l option in printf makes it a long string, and I believe you need the "call" statement because the ordinary gdb printf doesn't like that option.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文