10

I'm debugging a python daemon on a embedded Linux board. I ssh to the board on which I run the program and enter the debugger. Given that it's a deamon process I'm using rdb from celery

#Install on the system
pip3 install celery

# Set in the code
from celery.contrib import rdb
rdb.set_trace()

# Connect to the debugger
telnet localhost 5899

However in that session the tab key doesn't result in auto completion as usually in pdb and the up key doesn't scroll through history but prints a ^[[A.

The issues like these are related to the missing readline python module, however in this particular case the module is present and can be imported.

TheMeaningfulEngineer
  • 15,679
  • 27
  • 85
  • 143
  • 1
    @DaviLima, I believe you should use this https://stackoverflow.com/a/9809574/2830850 – Tarun Lalwani May 21 '18 at 15:43
  • @TarunLalwani, thanks, it sounds good but unfortunately it doesn't work inside a Docker container: `rlwrap: error: My terminal reports width=0 (is it emacs?) I can't handle this, sorry!` – Davi Lima May 26 '18 at 11:37
  • 1
    @DaviLima, can you run `stty rows 50 && stty cols 150` in your terminal before running the `rlwrap` command see if that helps – Tarun Lalwani May 26 '18 at 12:13
  • @TarunLalwani, thanks, that solves with the arrows! Lastly, tab is still missing, though. Now nothing gets outputted when I press it, but it doesn't autocomplete either. Would you have any other hint? – Davi Lima May 27 '18 at 07:36
  • It looks like it's possible to enable TABs but more complicated than one would enjoy. Answer by @HansLub, rlwrap's author: https://stackoverflow.com/a/9219349/462849 Plus, I couldn't find a Python/pdb/pdbpp/rdb example. If anyone knows of one, it'd be very welcome, maybe we could even repackage it with the stty+rlwrap+nc commands as an one step solution... – Davi Lima May 27 '18 at 12:10

2 Answers2

4

I'm not sure what the issue is, and might be telnet related. A workaround it to use another remote debugger that seems to work:

#Install on the system
pip3 install epdb

# Set in the code
import epdb; epdb.serve()

# Connect to the debugger
python3 -c 'import epdb; epdb.connect()'

Given that this is just a workaround, won't accept it as an answer.

TheMeaningfulEngineer
  • 15,679
  • 27
  • 85
  • 143
  • Hi, thanks for the answer! My connection to the debugger closes after 60 seconds, saying (Epdb) *** Connection closed by remote host ***. Any tips to extend the connection? – aerin May 12 '21 at 06:09
  • Ok, for anyone having connection timeout, it can be solved by adding `--soft-time-limit 9999999` on your celery command. – aerin May 12 '21 at 14:49
3

So your possible options are

rlwrap

rlwrap telnet host port

if you have col and rows issue run below

stty rows 50 && stty cols 150

socat

socat readline tcp:127.0.0.1:6900

This will add readline and history support without needing anything else like a rlwrap

I couldn't find a way as of yet to enable Telnet with tab completion. There are few interesting SO threads which talk about putting telnet client in a nolinemode or charactermode

Force telnet client into character mode

I tried updating Rdb code to implement but all attempts failed as such

PS: Credits to https://stackoverflow.com/a/9809574/2830850 and https://stackoverflow.com/a/9219349/462849

Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265
  • `socat readline tcp:127.0.0.1:6900` fails with `socat[177] E unknown device/address "readline"` even if I run `stty` first and prefix it with `rlwrap` as suggested in https://github.com/vxgmichel/aioconsole/issues/7#issuecomment-340092424 Running a Docker container with `Linux version 4.4.0-1052-aws (buildd@lgw01-amd64-031) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.9) )` – Davi Lima May 28 '18 at 13:35
  • You need to have readline libraries installed inside the docker container – Tarun Lalwani May 28 '18 at 13:51