On Thu, Mar 10, 2022 at 1:01 PM Rob Whitlock <rwhitloc...@gmail.com> wrote:
> On Wed, Mar 9, 2022 at 11:20 PM Philip Guenther <guent...@gmail.com> > wrote: > >> On Wed, Mar 9, 2022 at 8:28 AM Rob Whitlock <rwhitloc...@gmail.com> >> wrote: >> >>> I'm trying to attach gdb to an already running cwm but I get the >>> following >>> error: >>> >>> ptrace: Invalid argument. >>> >>> Why am I getting this error? Also, I have already set >>> kern.global_ptrace=1, >>> and both cwm and gdb are being run by the same user. This problem occurs >>> both with the gdb in base and the gdb/egdb in ports. >>> >> >> Let me guess: the cwm process is an ancestor of the shell where you're >> invoking gdb. We don't permit that as the reparenting done by ptrace() >> would create a loop in the process tree, which breaks assumptions by both >> kernel and userspace programs. If that's the case, run gdb from an ssh >> session or something like that. >> >> Hmm, I guess I never updated the ptrace(2) manpage to mention that... >> >> Philip Guenther >> > > Thanks, that fixed the problem. I decided to go about breaking the loop in > the process tree in a slightly different (maybe some would say quick and > dirty) way, which I'll describe here in case someone else has this problem. > If you start an xterm from your ~/.xsession (or whatever startup script > you're using) and do *not* exec your window manager, then that xterm will > not be a child of your window manager. If you then try to attach gdb to > your window manager, you won't get the error. In order to not have to > restart your X session in case you close that special xterm, you can put > the command to run xterm in a loop. > > while true; do xterm; done & > cwm # not "exec cwm" > > Robert > It seems this was more "quick and dirty" than I realized, as the backgrounded loop doesn't exit when X does, so it's probably better to just ignore this way of doing it and use ssh like Philip Gunther said. Robert