Skip to content

Instantly share code, notes, and snippets.

@joonty
Last active July 4, 2020 13:45
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joonty/3348076 to your computer and use it in GitHub Desktop.
Save joonty/3348076 to your computer and use it in GitHub Desktop.
Patch for client.py, part of the Komodo Python remote debugger. Fixes an exception being raised when "eval" is used, for versions 7.1.0 and 8.5.0.
3249,3250c3249
< _eval_optlist = [['i','transaction_id', int, 1, -1, None],
< ['l','length', int, 1, 0, None]]
---
> _eval_optlist = [['i','transaction_id', int, 1, -1, None]]
3252c3251
< (tid, data_length, data,) = self._getopts(cmdargs, self._eval_optlist, "eval")
---
> (tid, data,) = self._getopts(cmdargs, self._eval_optlist, "eval")
3268,3269c3267,3268
< prop = Property(None, None, value, self._data_encoding,
< self._show_hidden, hiddenContextTypes[context_id])
---
> prop = Property(data, data, value, self._data_encoding,
> self._show_hidden, hiddenContextTypes[0])
3426,3427c3426
< _eval_optlist = [['i','transaction_id', int, 1, -1, None],
< ['l','length', int, 1, 0, None]]
---
> _eval_optlist = [['i','transaction_id', int, 1, -1, None]]
3429c3428
< (tid, data_length, data,) = self._getopts(cmdargs, self._eval_optlist,
"eval")
---
> (tid, data,) = self._getopts(cmdargs, self._eval_optlist, "eval")
3445,3446c3444,3445
< prop = Property(None, None, value, self._data_encoding,
< self._show_hidden, hiddenContextTypes[context_id])
---
> prop = Property(data, data, value, self._data_encoding,
> self._show_hidden, hiddenContextTypes[0])
@x-yuri
Copy link

x-yuri commented Aug 10, 2018

Here's what worked for me:

$ curl 'http://downloads.activestate.com/Komodo/releases/archive/8.x/8.5.4/remotedebugging/Komodo-PythonRemoteDebugging-8.5.4-86985-linux-x86_64.tar.gz?_ga=2.213132828.928515719.1533909623-2080295309.1533909623' -o Komodo-PythonRemoteDebugging-8.5.4-86985-linux-x86_64.tar.gz
$ tar xf Komodo-PythonRemoteDebugging-8.5.4-86985-linux-x86_64.tar.gz
$ cd Komodo-PythonRemoteDebugging-8.5.4-86985-linux-x86_64
$ cp -r python3lib/dbgp .

// the following patch fixes expression evaluation
$ curl -L https://gist.githubusercontent.com/x-yuri/1ec2e2a67b5c2aae994668b7bde6fd4d/raw/854bcdd1ce2c3de856b89c4024a7b53c30fd7c67/client.py.patch -o dbgp/client.py.patch
$ patch dbgp/client.py < dbgp/client.py.patch

// the following patch allows to debug scripts that behave differently
// depending on basename($0) (symlink)
// e.g. ansible-playbook
// or else it would think it's run as ansible
$ curl -L https://gist.githubusercontent.com/x-yuri/1ec2e2a67b5c2aae994668b7bde6fd4d/raw/854bcdd1ce2c3de856b89c4024a7b53c30fd7c67/pydbgp.patch -o pydbgp.patch
$ patch pydbgp < pydbgp.patch

// <F5> in vim
$ path/to/pypdbg -d localhost:9000 /path/to/script

More or less worked. I still have issues with setting breakpoints in arbitrary scripts. It must have to do with anisble creating worker processes.

@bitwombat
Copy link

If you're happy to use Komodo-PythonRemoteDebugging-11.1.0-91033, this might work. Same edits as above, just different line numbers.

--- client.py	2020-06-21 14:32:45.269921276 +1000
+++ client.py.orig	2020-06-21 14:23:37.376844510 +1000
@@ -3433,10 +3433,10 @@
         _template = '<response xmlns="urn:debugger_protocol_v1" command="breakpoint_list" transaction_id="%s">%s</response>'
         self.socket.send_response(_template % (tid, bpinfo))
 
-    _eval_optlist = [['i','transaction_id', int, 1, -1, None]]
-
+    _eval_optlist = [['i','transaction_id', int, 1, -1, None],
+                ['l','length', int, 1, 0, None]]
     def do_eval(self, cmdargs, *args):
-        (tid, data,) = self._getopts(cmdargs, self._eval_optlist, "eval")
+        (tid, data_length, data,) = self._getopts(cmdargs, self._eval_optlist, "eval")
         
         # read data_length from the socket
         if self._data_encoding == 'base64':
@@ -3452,8 +3452,8 @@
             raise CommandError('eval', tid, ERROR_EVAL_FAILED,
                            'eval of expression failed: '+str(e))
 
-        prop = Property(data, data, value, self._data_encoding,
-                            self._show_hidden, hiddenContextTypes[0])
+        prop = Property(None, None, value, self._data_encoding,
+                            self._show_hidden, hiddenContextTypes[context_id])
         
         _template = '<response xmlns="urn:debugger_protocol_v1" command="eval" transaction_id="%s">%s</response>'
 

@gilbh
Copy link

gilbh commented Jul 4, 2020

I verified that client.py was patched (as shown in all above codes) but still I am getting the same error:
required argument [l:length] missing

-- any idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment