编写一个Iron Python调试器 [英] Writing an Iron Python debugger

查看:177
本文介绍了编写一个Iron Python调试器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为一个学习练习,我使用IronPython编写了一个简单的扩展/插件/宏框架 - 我已经了解了基础知识,但是我想添加一些基本的调试支持,使我的脚本编辑器更易于使用



我已经在互联网上狩猎了一下,我在编写托管调试器时找到了一些很好的资源(包括Mike Stall的优秀。Net Debugging blog 和MSDN文档在 CLR调试API ) - 我知道IronPython本质上是IL,但是除了我以外,特别是:




  • 将动态语言(如IronPython)调试为静态语言(如C#)之间有什么显着的区别吗?

  • 我需要以特殊的方式执行我的脚本t IronPython输出合适的调试信息?

  • 调试在当前进程中运行的脚本会导致死锁,还是IronPython在子进程中执行我的脚本?

  • 我最好先研究如何制作一个简单的C#调试器,以获得一般的想法?



(I对于现在调试器的GUI方面我并不感兴趣 - 我已经有一个很好的想法,这可能如何工作)

解决方案

还有一些链接已经开始变得更加清晰了 - 有两种添加调试器支持的方法,我看到:



将IronPython调试为一个CLR应用程序



第一个是使用IronPython发出IL并使用用于调试.Net应用程序的标准技术进行调试的事实。 Harry Pierson有一系列关于这个方法的博客文章这里关于ipydbg的开发 - 一个使用这种方法的python调试器。




  • 请参阅这篇文章,概述了.Net调试功能在哪里公开,以及它周围的各种包装(mdbg)

  • 这种方法的缺点是这种调试方式完全阻止了被调试的应用程序,因此您必须在第二个应用程序中执行脚本。



< h2>使用Microsoft.Scripting.Debugging

由于这个限制,Microsoft.Scripting.Debugging库被编译而不是远适用于运行IronPython嵌入(即在同一个过程中)。



有一个介绍这里以及更广泛的博客文章如何使用这里 - 本质上它由回调函数组成,每次任何有趣的发生(每次我们进入一个函数,每次从函数返回,每次执行一行)。脚本的执行在回调函数运行时被阻止,这允许您打破脚本。



我决定采取第二种方法 - 我会更新这篇文章,因为我发现更多的信息可能有助于其他人尝试这样做。


As a learning exercise I'm writing myself a simple extension / plugin / macro framework using IronPython - I've gotten the basics working but I'd like to add some basic debugging support to make my script editor easier to work with.

I've been hunting around on the internet a bit and I've found a couple of good resources on writing managed debuggers (including Mike Stall's excellent .Net Debugging blog and the MSDN documentaiton on the CLR Debugging API) - I understand that IronPython is essentially IL however apart from that I'm a tad lost on how to get started, in particular:

  • Are there any significant differences between debugging a dynamic language (such as IronPython) to a static one (such as C#)?
  • Do I need to execute my script in a special way to get IronPython to output suitable debugging information?
  • Is debugging a script running inside the current process going to cause deadlocks, or does IronPython execute my script in a child process?
  • Am I better off looking into how to produce a simple C# debugger first to get the general idea?

(I'm not interested in the GUI aspect of making a debugger for now - I've already got a pretty good idea of how this might work)

解决方案

A few more links have started to make this a lot clearer - there are 2 ways of adding debugger support that I've seen:

Debugging IronPython as a CLR application

The first is to use the fact that IronPython emits IL and debug it using standard techniques used for debugging .Net apps. There is a series of blog posts on this approach by Harry Pierson here about the development of ipydbg - a python debugger that uses this approach.

  • See this post for an overview on where .Net debugging functionality is exposed, and the various wrappers around it (mdbg)
  • The disadvantage of this approach is that this form of debugging completely blocks the application being debugged, and so you must execute your scripts in a second application.

Using Microsoft.Scripting.Debugging

Because of this limitation the Microsoft.Scripting.Debugging library was produced instead which is far more suited to for applications which run IronPython "embedded" (i.e. in the same process).

There is an introduction to it here and a more extensive blog post on how it used here - essentially it consists of a callback function which is executed every time anything "interesting" happens (every time we enter a function, every time we return from a function and every time a line is executed). Execution of the script is blocked while the callback function is running, which allows you to "break" the script.

I've decided to take the second approach - i'll update this post as I find more information that might be helpful to other trying to do this.

这篇关于编写一个Iron Python调试器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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