如何使用 xdebug 和 sublime 来调试 python 脚本 [英] How to use xdebug with sublime to debug python script

查看:38
本文介绍了如何使用 xdebug 和 sublime 来调试 python 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图从更重的 IDE 转向 sublime.我注意到它与 Intellij IDE 相比缺少调试.通过研究我了解了 XDebug,我相信它可以提供类似的调试.但是,我在设置时遇到了问题.

这是我所做的:

  1. 安装 sublime 3
  2. 安装包管理器
  3. 使用包管理器安装 XDebug
  4. 注意到的文件丢失了,所以我通过包管理器删除了包
  5. 从 martomo 克隆存储库 ( 令人惊讶的是,其中包含有关在您的服务器上安装和设置工作 Xdebug 系统的重要信息.您可能错过的第一条重要信息是 Xdebug 是 PHP 服务器的扩展.这是可以理解的,你可能很着急,无论如何都想开始.但是,如果您一直阅读(仍然恰当地命名)自述文件,您会找到指向 xdebug.org 网站的链接,了解有关在您的服务器上安装扩展的详细信息,然后是标题为 Configuration 引导读者浏览 .sublime-settings 文件,以及已经提供的深思熟虑的评论.最后,有一个名为 Troubleshoot 的部分,它会引导您开始会话、设置断点和监视表达式、异常处理、自定义布局等等.所有这些文档都应该使 PHP 开发人员能够启动并运行它.希望下次您遇到类似情况时,您会检查一下.

    Trying to move to sublime from heavier IDEs. The thing I noticed it lacked was debugging compared to the intellij IDEs. Through research I learned about XDebug and I believe it can provide comparable debugging. However, I'm having trouble setting it up.

    Here is what I've done:

    1. Installed sublime 3
    2. Installed package manager
    3. Used package manager to install XDebug
    4. Noticed files were missing so I deleted the package through the package manager
    5. Cloned the repo from martomo (https://github.com/martomo/SublimeTextXdebug)
    6. Placed it in my Packaged folder

    7. Then I went to XDebug.sublime-settings and I'm not sure how to configure it (what am I linking to, what url does it need, etc...)

      {
          // For remote debugging to resolve the file locations
          // it is required to configure the path mapping
          // with the server path as key and local path as value.
          //
          // Make sure to use absolute path when defining server path,
          // because Xdebug debugger engine does not return symbolic links.
          //
          // Example:
          // "/absolute/path/to/file/on/server" : "/path/to/file/on/computer",
          // "/var/www/htdocs/example/" : "C:/git/websites/example/"
          "path_mapping": {
      
          },
      
          // Determine which URL to launch in the default web browser
          // when starting/stopping a session.
          "url": "",
      
          // An IDE key is used to identify with debugger engine
          // when Sublime Text will start or stop a debugging session.
          //
          // This package does not filter sessions by IDE key,
          // it will accept any IDE key, also ones that do not match this configured IDE key.
          // It is merely used when launching the default web browser with the configured URL.
          "ide_key": "sublime.xdebug",
      
          // Which port number Sublime Text should listen
          // to connect with debugger engine.
          "port": 9000,
      
          // Show super globals in context view.
          "super_globals": true,
      
          // Maximum amount of array children
          // and object's properties to return.
          "max_children": 32,
      
          // Maximum amount of
          // variable data to initially retrieve.
          "max_data": 1024,
      
          // Maximum amount of nested levels to retrieve
          // of array elements and object properties.
          "max_depth": 1,
      
          // Break at first line on session start, when debugger engine has connected.
          "break_on_start": false,
      
          // Break on exceptions, suspend execution
          // when the exception name matches an entry in this list value.
          "break_on_exception": [
              // E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR
              "Fatal error",
              // E_RECOVERABLE_ERROR (since PHP 5.2.0)
              "Catchable fatal error",
              // E_WARNING, E_CORE_WARNING, E_COMPILE_WARNING, E_USER_WARNING
              "Warning",
              // E_PARSE
              "Parse error",
              // E_NOTICE, E_USER_NOTICE
              "Notice",
              // E_STRICT
              "Strict standards",
              // E_DEPRECATED, E_USER_DEPRECATED (since PHP 5.3.0)
              "Deprecated",
              // 0
              "Xdebug",
              // default
              "Unknown error"
          ],
      
          // Always close debug windows and restore layout on session stop.
          "close_on_stop": false,
      
          // Do not show possible password values in context output.
          "hide_password": false,
      
          // Show in output parsed response instead of raw XML.
          "pretty_output": false,
      
          // Always launch browser on session start/stop.
          // Note: This will only work if you have the 'url' setting configured.
          "launch_browser": false,
      
          // When launching browser on session stop do not execute script.
          // By using parameter XDEBUG_SESSION_STOP_NO_EXEC instead of XDEBUG_SESSION_STOP.
          "browser_no_execute": false,
      
          // Do not use the debugging window layout.
          "disable_layout": false,
      
          // Window layout that is being used when debugging.
          "debug_layout" : {
              "cols": [0.0, 0.5, 1.0],
              "rows": [0.0, 0.7, 1.0],
              "cells": [[0, 0, 2, 1], [0, 1, 1, 2], [1, 1, 2, 2]]
          },
      
          // Group and index positions for debug views.
          "breakpoint_group": 2,
          "breakpoint_index": 1,
          "context_group": 1,
          "context_index": 0,
          "stack_group": 2,
          "stack_index": 0,
          "watch_group": 1,
          "watch_index": 1,
      
          // Custom gutter icons for indicating current line or enabled/disabled breakpoints.
          //
          // Do not use same icon for following values, because Sublime Text is unable
          // to use the same icon for different scopes, in case there are duplicate icons
          // detected it will fall back to the corresponding icon in the package.
          "breakpoint_enabled": "circle",
          "breakpoint_disabled": "dot",
          "breakpoint_current": "",
          "current_line": "bookmark",
      
          // Path to Python installation on your system.
          // Which is being used to load missing modules.
          //
          // It is recommended to configure your Python path for Sublime Text 2
          // especially on older UNIX systems, where some modules (xml.parsers.expat)
          // might be missing and could improve performance of package.
          //
          // Example:
          // "python_path" : "/usr/lib/python2.7"
          "python_path" : "",
      
          // Show detailed log information about communication
          // between debugger engine and Sublime Text.
          // Log can be found at Packages/User/Xdebug.log
          "debug": false
      }
      

    8. I left the XDebug.sublime-settings file alone and just ran the debugger.

    9. Went to http://localhost:9000 (and nothing happened, it just kind of got stuck loading)

    The script I want to debug is in /Users/wf/Desktop (the file is xdebugTest.py)

    How should I set up the url? (I tried http://localhost:9000/Users/wf/Desktop/xdebugTest.py and 404)

    I'll appreciate any help setting up the debugging parameters.
    Thanks you.

    解决方案

    If you were on Github to clone the source, you should have run across the README which, surprisingly, contains important information regarding installing and setting up a working Xdebug system on your server. The first important piece of information you probably missed is that Xdebug is an extension for PHP servers. It's understandable, you were probably in a hurry and wanted to get started no matter what. However, if you'd kept reading the (still aptly-named) README, you would have found links to the xdebug.org website for details on installing the extension on your server, then a comprehensive section entitled Configuration which guides the reader through each item in the .sublime-settings file, in addition to the thoughtful comments which are already provided. Finally, there is a section called Troubleshoot which leads you through starting a session, setting breakpoints and watch expressions, exception handling, customizing the layout, and more. All of which documentation should enable even a PHP developer to get this up and running. Hopefully the next time you're in a similar situation you'll check it out.

    这篇关于如何使用 xdebug 和 sublime 来调试 python 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆