小编Sew*_*cca的帖子

Windows 上的 VSCode:gdb 不会在“抛出”时中断,但会在常规异常时中断

在调试我的代码时,gdb 捕获常规异常(例如除以零),但不捕获使用throw.

我希望 vscode 能够跳转到抛出异常的位置,这样我就可以进行调查。相反,异常会导致应用程序终止并关闭调试器。

我用一些虚拟代码测试了它:

编译为:g++ -g main.cpp -o test.exe

#include <stdexcept>
#include <iostream>

void test()
{
    throw std::invalid_argument( "received negative value" );
}

int main(int argc, char const *argv[]) {
    std::cin.get();

    // int c = 1 / 0;
    test();

    std::cout << "v";

    std::cin.get();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:

terminate called after throwing an instance of 'std::invalid_argument'
  what():  received negative value

This application has requested the Runtime to terminate it in an unusual way.
Please contact the …
Run Code Online (Sandbox Code Playgroud)

c++ windows gdb windows-7 visual-studio-code

7
推荐指数
1
解决办法
5508
查看次数

如何使用 VSCode 调试 Lua Love2D?

我正在寻找有关如何在Visual Studio Code中调试 Lua Code 的建议。我正在使用Love2D,所以我知道我需要以某种方式嵌入我的调试代码,因为它不是独立的 Lua,但是我更喜欢对我的源代码进行最小程度的增强。

目标:在 VSCode 中使用断点、捕获错误和变量检查进行定期调试。我不介意使用哪个扩展,只要我可以轻松调试我的代码即可。

到目前为止我尝试过的:

  1. Lua 调试器:它以某种方式工作,它遇到了断点,但只有在调用时debuggee.poll()我无法介入或进一步检查。

  2. LRDB:看起来很有希望,但不知何故游戏无法开始。它只是挂起,直到我用任务管理器杀死它。

LRDB 的代码(不包括通用更新/绘制函数,因为它们仅用于测试断点):


local lrdb = require "lrdb_server"
local db_port = 21110

function love.run()
    lrdb.activate(db_port)

    if love.load then love.load(love.arg.parseGameArguments(arg), arg) end
 
    -- We don't want the first frame's dt to include time taken by love.load.
    if love.timer then love.timer.step() end
 
    local dt = 0
    lrdb.deactivate()
    -- Main loop time.
    return function()
        lrdb.activate(db_port)
        -- Process events.
        if love.event then
            love.event.pump() …
Run Code Online (Sandbox Code Playgroud)

lua love2d visual-studio-code

7
推荐指数
1
解决办法
3716
查看次数

如何使用 pyside 正确设置 vscode?缺少建议

我对 pyside、qt 和 python 很陌生。我设法设置一个带有基本窗口和关闭应用程序的按钮的项目。我的问题是,尽管代码可以很好地运行,但 vscode 不会显示所有可用的属性。 vscode-pyside2-问题-1.png 请注意除了 signal 之外,如何建议一堆其他属性clicked。如果我将鼠标悬停在 上clicked,它会告诉我clicked: Any 仅在调试期间,vscode 会告诉我单击的是什么: vscode-pyside2-问题-2.png 当前设置:

  • 操作系统:Linux
  • Virtualenv 已pyside2安装
  • 使用ms-python.python和ms-python.vscode-pylance
  • ui/MainWindow.ui文件和相应的生成ui/MainWindow_ui.ui文件pyside2-uic

python pyside visual-studio-code pyside2

6
推荐指数
1
解决办法
3891
查看次数

str.replace(/^/gm, "\t") 的预期行为是什么

我希望str.replace(/^/gm, "\t")在每一行前面插入一个\t. 似乎是这样,但仅当使用 LF 结尾时,当使用 CRLF 结尾时,会发生一些奇怪的事情,它也会将其插入到\r\n.

考虑这个示例代码:

var str1 = "First line\nnext Line";
var str2 = "First line\r\nnext Line";

function escape(str) {
  return str.replace(/[\r\n\t]/g, match => {
    return {
      '\r': '\\r',
      '\n': '\\n',
      '\t': '\\t',
    }[match]
  })
}

console.log("First string:")
console.log(escape(str1))


console.log("Second string:")
console.log(escape(str2))

function operation(str) {
  return str.replace(/^/gm, "\t");
}

console.log("First string:")
str1 = operation(str1)
console.log(escape(str1))


console.log("Second string:")
str2 = operation(str2)
console.log(escape(str2))
Run Code Online (Sandbox Code Playgroud)
.as-console-wrapper {
    max-height: 100% !important;
}
Run Code Online (Sandbox Code Playgroud)

转换后,第一个字符串符合预期\tFirst line\n\tnext Line …

javascript typescript

3
推荐指数
1
解决办法
86
查看次数