Bug 13984 - gdb stops controlling a thread after "Remote 'g' packet reply is too long: ..." error message
Summary: gdb stops controlling a thread after "Remote 'g' packet reply is too long: .....
Status: UNCONFIRMED
Alias: None
Product: gdb
Classification: Unclassified
Component: server (show other bugs)
Version: 7.4
: P2 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-16 02:34 UTC by curty
Modified: 2017-02-13 08:58 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
gdb/remote.c change set (33.35 KB, image/png)
2015-08-12 11:47 UTC, Mehmet Ali SARIKAYA
Details
gdb-7.9/gdb/remote.c patch file (454 bytes, patch)
2015-08-12 17:08 UTC, Mehmet Ali SARIKAYA
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description curty 2012-04-16 02:34:25 UTC
Linux Kernel debugging running gdbserver at Eclipse causes gdbserver stop receiving thread commands after "Remote 'g' packet reply is too long: ..." error message. This message arrives after hit a tbreak at start_kernel() function.

The state is "Thread [1] (Suspended)" but when I try to control this thread (eg. execute, suspend, etc), a "Cannot execute this command while the selected thread is running" message returns and it is not possible to continue debuging.

> QEMU Guest (Intel i7) command:

# /home/curtyc/000_HPC/usr/local/packages/qemu-devel/bin/qemu-system-x86_64 -smp 1 -kernel '/home/curtyc/Linux_kernel_source/linux-3.3/arch/x86_64/boot/vmlinux' /home/curtyc/QEMU/images/Fedora-x86_64-linux-3.3.0.raw -S -gdb tcp::1234


> GDB console at Eclipse:

------ cut here -------
.gdbinit: No such file or directory.
Reading symbols from /home/curtyc/Linux_kernel_source/linux-3.3/vmlinux...done.
866-gdb-set confirm off
866^done
(gdb) 
867-gdb-set width 0
867^done
(gdb) 
868-gdb-set height 0
868^done
(gdb) 
869-interpreter-exec console echo
869^done
(gdb) 
870-gdb-show prompt
870^done,value="(gdb) "
(gdb) 
871-gdb-set auto-solib-add off
871^done
(gdb) 
872-gdb-set stop-on-solib-events 0
872^done
(gdb) 
873-target-select remote localhost:1234
=thread-group-started,id="i1",pid="42000"
=thread-created,id="1",group-id="i1"
*stopped,frame={addr="0x0000000000000000",func="irq_stack_union",args=[]},thread-id="1",stopped-threads="all"
873^connected
(gdb) 
874 info proc
&"info proc\n"
&"Can't determine the current process's PID: you must name one.\n"
874^error,msg="Can't determine the current process's PID: you must name one."
(gdb) 
875-environment-cd /home/curtyc/Linux_kernel_source/linux-3.3
875^done
(gdb) 
876 info program
&"info program\n"
~"Debugging a target over a serial line.\n"
~"Program stopped at 0x0.\n"
~"It stopped with signal SIGTRAP, Trace/breakpoint trap.\n"
876^done
(gdb) 
877 info threads
&"info threads\n"
~"  Id   Target Id         Frame \n"
~"* 1    Thread 1 (CPU#0 [running]) 0x0000000000000000 in irq_stack_union ()\n"
877^done
(gdb) 
878-stack-info-depth
878^done,depth="2"
(gdb) 
879-stack-list-frames 0 2
879^done,stack=[frame={level="0",addr="0x0000000000000000",func="irq_stack_union"},frame={level="1",addr="0x0000000000000000",func="??"}]
(gdb) 
880-data-list-changed-registers
880^done,changed-registers=["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","73","74","75","76","77","78","79","80","81","82","83","84","85","86","87","88","89","90","91","92","93","94","95","96","97","98","99","100","102","103","104","105","106","107","108","109","110","111","112","113","114","115","116","117","118","119","120","121","122","123","124","125"]
(gdb) 
881 info sharedlibrary
&"info sharedlibrary\n"
~"No shared libraries loaded at this time.\n"
881^done
(gdb) 
882-environment-directory

...
<many_directory_paths_excluded_without_problem_for_understanding>
...

(gdb) 
883-data-list-register-names
883^done,register-names=["rax","rbx","rcx","rdx","rsi","rdi","rbp","rsp","r8","r9","r10","r11","r12","r13","r14","r15","rip","eflags","cs","ss","ds","es","fs","gs","st0","st1","st2","st3","st4","st5","st6","st7","fctrl","fstat","ftag","fiseg","fioff","foseg","fooff","fop","xmm0","xmm1","xmm2","xmm3","xmm4","xmm5","xmm6","xmm7","xmm8","xmm9","xmm10","xmm11","xmm12","xmm13","xmm14","xmm15","mxcsr","","","","","","","","","","","","","","","","","orig_rax","al","bl","cl","dl","sil","dil","bpl","spl","r8l","r9l","r10l","r11l","r12l","r13l","r14l","r15l","ah","bh","ch","dh","ax","bx","cx","dx","si","di","bp","","r8w","r9w","r10w","r11w","r12w","r13w","r14w","r15w","eax","ebx","ecx","edx","esi","edi","ebp","esp","r8d","r9d","r10d","r11d","r12d","r13d","r14d","r15d"]
(gdb) 
884-break-insert -t init/main.c:start_kernel
884^done,bkpt={number="1",type="breakpoint",disp="del",enabled="y",addr="0xffffffff81cf083e",func="start_kernel",file="init/main.c",fullname="/home/curtyc/Linux_kernel_source/linux-3.3/init/main.c",line="464",times="0",original-location="init/main.c:start_kernel"}
(gdb) 
885-exec-continue
885^running
*running,thread-id="all"
(gdb) 
885^error,msg="Remote 'g' packet reply is too long: 00000000000000000090f700000000000090f70100000000020000000000000080dfd781ffffffffb0dfd781ffffffff781fc081ffffffff601fc081ffffffff0090f7000000000000000001000000000090f700000000000000000100000000200000000000000000f0dd81ffffffffa81fc081ffffffff00c00800000000003e08cf81ffffffff9600000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007f0300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000801f0000"
(gdb) 
886 info threads
&"info threads\n"
~"  Id   Target Id         Frame \n"
~"* 1    Thread 1 (CPU#0 [running]) (running)\n"
886^done
(gdb) 
887-stack-info-depth
887^error,msg="Target is executing."
(gdb) 
888-stack-info-depth
888^error,msg="Target is executing."
(gdb) 
889-stack-list-frames 0 1
889^error,msg="Target is executing."
(gdb) 
890-data-list-changed-registers
890^error,msg="Target is executing."
(gdb) 
------ cut here -------

Thanks in advance for your attention.
Comment 1 Mehmet Ali SARIKAYA 2015-08-12 11:47:55 UTC
Created attachment 8506 [details]
gdb/remote.c change set

6064 /* Further sanity checks, with knowledge of the architecture. 
6065 //SunnyBeike
6066 
6067 // if (buf_len  > 2 * rsa->sizeof_g_packet) 
6068 // error (_("Remote 'g' packet reply is too long: %s"), rs->buf); 
6069 
6070    if(buf_len > 2 * rsa->sizeof_g_packet) {
6071         rsa->sizeof_g_packet = buf_len;
6072         for(i = 0; i < gdbarch_num_regs(gdbarch); i++){
6073             if(rsa->regs->pnum == -1)
6074                continue;
6075             if(rsa->regs->offset >= rsa->sizeof_g_packet)
6076                rsa->regs->in_g_packet = 0;
6077             else
6078                rsa->regs->in_g_packet = 1;
6079         } 
6080    }
6081
Comment 2 Mehmet Ali SARIKAYA 2015-08-12 11:49:41 UTC
6064 /* Further sanity checks, with knowledge of the architecture. 
6065 //SunnyBeike
6066 
6067 // if (buf_len  > 2 * rsa->sizeof_g_packet) 
6068 // error (_("Remote 'g' packet reply is too long: %s"), rs->buf); 
6069 
6070    if(buf_len > 2 * rsa->sizeof_g_packet) {
6071         rsa->sizeof_g_packet = buf_len;
6072         for(i = 0; i < gdbarch_num_regs(gdbarch); i++){
6073             if(rsa->regs->pnum == -1)
6074                continue;
6075             if(rsa->regs->offset >= rsa->sizeof_g_packet)
6076                rsa->regs->in_g_packet = 0;
6077             else
6078                rsa->regs->in_g_packet = 1;
6079         } 
6080    }
6081


/* These changes solve problem for newer version of gdb like 7.8* and 7.9* */
Comment 3 Mehmet Ali SARIKAYA 2015-08-12 11:50:22 UTC
Comment on attachment 8506 [details]
gdb/remote.c change set

6064 /* Further sanity checks, with knowledge of the architecture. 
6065 //SunnyBeike
6066 
6067 // if (buf_len  > 2 * rsa->sizeof_g_packet) 
6068 // error (_("Remote 'g' packet reply is too long: %s"), rs->buf); 
6069 
6070    if(buf_len > 2 * rsa->sizeof_g_packet) {
6071         rsa->sizeof_g_packet = buf_len;
6072         for(i = 0; i < gdbarch_num_regs(gdbarch); i++){
6073             if(rsa->regs->pnum == -1)
6074                continue;
6075             if(rsa->regs->offset >= rsa->sizeof_g_packet)
6076                rsa->regs->in_g_packet = 0;
6077             else
6078                rsa->regs->in_g_packet = 1;
6079         } 
6080    }
6081
Comment 4 Ciro Santilli 2015-08-12 12:55:24 UTC
@Mehmet can you please make a patch, send to the mailing list, and keep pinging weekly until it gets reviewed?

I reproduce this by taking the following steps:

    # On kernel 4.1, set `CONFIG_DEBUG_INFO` and `CONFIG_GDB_SCRIPTS`.
    qemu-system-x86_64 -kernel ../build/arch/x86/boot/bzImage -initrd rootfs.cpio.gz -S -s
    gdb -ex "add-auto-load-safe-path ${vmlinux_path}-gdb.py" \
        -ex "file ${vmlinux_path}" \
        -ex 'target remote localhost:1234'
    hbreak start_kernel
    continue

Then the:

    Remote 'g' packet reply is too long

message appears, QEMU stops (apparently at the right place) and for most commands I run, e.g. continue, GDB says:

    (gdb) continue
    Continuing.
    Cannot execute this command while the selected thread is running.

`list` shows the wrong lines, not at `start_kernel` but around line 15. It is the right file however: `init/main.c`.

If I do Ctrl + D GDB quits and QEMU continues booting as normal.
Comment 5 Ciro Santilli 2015-08-12 12:57:25 UTC
I'm on Ubuntu 14.04, GDB 7.7.1.

There has also been some discussion at: https://bugs.launchpad.net/ubuntu/+source/qemu-kvm/+bug/901944
Comment 7 Mehmet Ali SARIKAYA 2015-08-12 17:08:46 UTC
Created attachment 8512 [details]
gdb-7.9/gdb/remote.c patch file

I used this patch for solving "Remote 'g' packet reply is too long" error. This patch solves problems if you take "Remote 'g' packet reply is too long" error. 
I tested it with gdb 7.9 but it can also be a solution for older version.

After applying this patch, gdb must recompile.
Comment 8 Mehmet Ali SARIKAYA 2015-08-12 17:09:49 UTC
This patch will be a solution.
Comment 9 Ciro Santilli 2015-08-12 21:01:57 UTC
@Mehmet have you sent the patch to the mailing list / merged it yourself on the tree? I could not find it. If not, this should not be marked as RESOLVED yet.
Comment 10 Mehmet Ali SARIKAYA 2015-08-13 10:37:12 UTC
I do not send it mail list. One of people should confirm this patch.
Comment 11 Ciro Santilli 2015-08-13 10:39:48 UTC
@Mehmet from my (limited) experience, unless you ping the gdb-patches list weekly, this patch is more likely to remain forgotten :-) Well if want let's wait a bit and see, if it does not work I will email it myself and credit you of course.
Comment 12 Orgad Shaneh 2016-04-10 14:52:09 UTC
Hi,

I posted a similar patch[1]. Hope it gets accepted.

[1] https://sourceware.org/ml/gdb-patches/2016-04/msg00200.html
Comment 13 Orgad Shaneh 2016-04-12 05:12:16 UTC
I got this message when I tried to remotely debug a mips64-octeon-linux gdbserver 6.8 with GDB >= 7.5.

GDB <= 7.4.1 works well, but with 7.5 and up I receive this message and the debugger stops functioning.

The proposed patch (including my variant) fixes this issue for me.

Using a newer gdbserver (Cavium SDK3 comes with 7.6) might also be a solution, but we need to support the old one as well.
Comment 14 berte 2017-01-10 18:26:26 UTC
Hi all, 

I've same issue with gdb 7.12.

Also I found kinda workaround. If you remove -S paremeter passing to Qemu, gdb works as expected but you cannot catch boot phase breakpoints.

### Env Info
gdb -v
GNU gdb (Gentoo 7.12 vanilla) 7.12
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>


qemu-system-x86_64 --version
QEMU emulator version 2.8.0
Copyright (c) 2003-2016 Fabrice Bellard and the QEMU Project developers
Comment 15 honghe 2017-02-13 08:58:52 UTC
@Mehmet Ali SARIKAYA 
You patch works with GDB 7.12 on Ubuntu 14.04.
Thanks!