summaryrefslogtreecommitdiff
path: root/gdbstub.c
AgeCommit message (Collapse)Author
2020-04-07gdbstub: fix compiler complainingDenis Plotnikov
./gdbstub.c: In function ‘handle_query_thread_extra’: /usr/include/glib-2.0/glib/glib-autocleanups.h:28:10: error: ‘cpu_name’ may be used uninitialized in this function [-Werror=maybe-uninitialized] g_free (*pp); ^ ./gdbstub.c:2063:26: note: ‘cpu_name’ was declared here g_autofree char *cpu_name; ^ cc1: all warnings being treated as errors Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com> Message-Id: <20200326151407.25046-1-dplotnikov@virtuozzo.com> Reported-by: Euler Robot <euler.robot@huawei.com> Reported-by: Chen Qun <kuhn.chenqun@huawei.com> Reviewed-by: Miroslav Rezanina <mrezanin@redhat.com> Message-Id: <20200325092137.24020-1-kuhn.chenqun@huawei.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-Id: <20200403191150.863-7-alex.bennee@linaro.org>
2020-03-17gdbstub: Fix single-step issue by confirming 'vContSupported+' feature to gdbChangbin Du
Recently when debugging an arm32 system on qemu, I found sometimes the single-step command (stepi) is not working. This can be reproduced by below steps: 1) start qemu-system-arm -s -S .. and wait for gdb connection. 2) start gdb and connect to qemu. In my case, gdb gets a wrong value (0x60) for PC, which is an another bug. 3) After connected, type 'stepi' and expect it will stop at next ins. But, it has never stopped. This because: 1) We doesn't report ‘vContSupported’ feature to gdb explicitly and gdb think we do not support it. In this case, gdb use a software breakpoint to emulate single-step. 2) Since gdb gets a wrong initial value of PC, then gdb inserts a breakpoint to wrong place (PC+4). Not only for the arm target, Philippe has also encountered this on MIPS. Probably gdb has different assumption for different architectures. Since we do support ‘vContSupported’ query command, so let's tell gdb that we support it. Before this change, gdb send below 'Z0' packet to implement single-step: gdb_handle_packet: Z0,4,4 After this change, gdb send "vCont;s.." which is expected: gdb_handle_packet: vCont? put_packet: vCont;c;C;s;S gdb_handle_packet: vCont;s:p1.1;c:p1.-1 Signed-off-by: Changbin Du <changbin.du@gmail.com> Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-Id: <20200221002559.6768-1-changbin.du@gmail.com> [AJB: fix for static gdbstub] Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Luc Michel <luc.michel@greensocs.com> Message-Id: <20200316172155.971-29-alex.bennee@linaro.org>
2020-03-17gdbstub: do not split gdb_monitor_write payloadDamien Hedde
Since we can now send packets of arbitrary length: simplify gdb_monitor_write() and send the whole payload in one packet. Suggested-by: Luc Michel <luc.michel@greensocs.com> Signed-off-by: Damien Hedde <damien.hedde@greensocs.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20191211160514.58373-3-damien.hedde@greensocs.com> Message-Id: <20200316172155.971-28-alex.bennee@linaro.org>
2020-03-17gdbstub: change GDBState.last_packet to GByteArrayDamien Hedde
Remove the packet size upper limit by using a GByteArray instead of a statically allocated array for last_packet. Thus we can now send big packets. Also remove the last_packet_len field and use last_packet->len instead. Signed-off-by: Damien Hedde <damien.hedde@greensocs.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-Id: <20191211160514.58373-2-damien.hedde@greensocs.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20200316172155.971-27-alex.bennee@linaro.org>
2020-03-17gdbstub: extend GByteArray to read register helpersAlex Bennée
Instead of passing a pointer to memory now just extend the GByteArray to all the read register helpers. They can then safely append their data through the normal way. We don't bother with this abstraction for write registers as we have already ensured the buffer being copied from is the correct size. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Acked-by: David Gibson <david@gibson.dropbear.id.au> Reviewed-by: Damien Hedde <damien.hedde@greensocs.com> Message-Id: <20200316172155.971-15-alex.bennee@linaro.org>
2020-03-17gdbstub: move mem_buf to GDBState and use GByteArrayAlex Bennée
This is in preparation for further re-factoring of the register API with the rest of the code. Theoretically the read register function could overwrite the MAX_PACKET_LENGTH buffer although currently all registers are well within the size range. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Damien Hedde <damien.hedde@greensocs.com> Tested-by: Damien Hedde <damien.hedde@greensocs.com> Message-Id: <20200316172155.971-10-alex.bennee@linaro.org>
2020-03-17gdbstub: move str_buf to GDBState and use GStringAlex Bennée
Rather than having a static buffer replace str_buf with a GString which we know can grow on demand. Convert the internal functions to take a GString instead of a char * and length. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Damien Hedde <damien.hedde@greensocs.com> Tested-by: Damien Hedde <damien.hedde@greensocs.com> Message-Id: <20200316172155.971-9-alex.bennee@linaro.org>
2020-03-17gdbstub: stop passing GDBState * around and use globalAlex Bennée
We only have one GDBState which should be allocated at the time we process any commands. This will make further clean-up a bit easier. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Damien Hedde <damien.hedde@greensocs.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-Id: <20200316172155.971-8-alex.bennee@linaro.org>
2020-03-17gdbstub: make GDBState static and have common init functionAlex Bennée
Instead of allocating make this entirely static. We shall reduce the size of the structure in later commits and dynamically allocate parts of it. We introduce an init and reset helper function to keep all the manipulation in one place. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Damien Hedde <damien.hedde@greensocs.com> Message-Id: <20200316172155.971-7-alex.bennee@linaro.org>
2020-03-06hmp: Fail gracefully if chardev is already in useKevin Wolf
Trying to attach a HMP monitor to a chardev that is already in use results in a crash because monitor_init_hmp() passes &error_abort to qemu_chr_fe_init(): $ ./x86_64-softmmu/qemu-system-x86_64 --chardev stdio,id=foo --mon foo --mon foo QEMU 4.2.50 monitor - type 'help' for more information (qemu) Unexpected error in qemu_chr_fe_init() at chardev/char-fe.c:220: qemu-system-x86_64: --mon foo: Device 'foo' is in use Abgebrochen (Speicherabzug geschrieben) Fix this by allowing monitor_init_hmp() to return an error and passing any error in qemu_chr_fe_init() to its caller instead of aborting. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Message-Id: <20200224143008.13362-19-kwolf@redhat.com> Acked-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2020-01-08chardev: Use QEMUChrEvent enum in IOEventHandler typedefPhilippe Mathieu-Daudé
The Chardev events are listed in the QEMUChrEvent enum. By using the enum in the IOEventHandler typedef we: - make the IOEventHandler type more explicit (this handler process out-of-band information, while the IOReadHandler is in-band), - help static code analyzers. This patch was produced with the following spatch script: @match@ expression backend, opaque, context, set_open; identifier fd_can_read, fd_read, fd_event, be_change; @@ qemu_chr_fe_set_handlers(backend, fd_can_read, fd_read, fd_event, be_change, opaque, context, set_open); @depends on match@ identifier opaque, event; identifier match.fd_event; @@ static -void fd_event(void *opaque, int event) +void fd_event(void *opaque, QEMUChrEvent event) { ... } Then the typedef was modified manually in include/chardev/char-fe.h. Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> Acked-by: Corey Minyard <cminyard@mvista.com> Acked-by: Cornelia Huck <cohuck@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20191218172009.8868-15-philmd@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2019-08-28gdbstub: Fix handler for 'F' packetSandra Loosemore
Handling of the 'F' packet has been broken since commit 4b20fab101b9e2d0fb47454209637a17fc7a13d5, which converted it to use the new packet parsing infrastructure. Per the GDB RSP specification https://sourceware.org/gdb/current/onlinedocs/gdb/The-F-Reply-Packet.html the second parameter may be omitted, but the rewritten implementation was failing to recognize this case. The result was that QEMU was repeatedly resending the fileio request and ignoring GDB's replies of successful completion. This patch restores the behavior of the previous code in allowing the errno parameter to be omitted and passing 0 to the callback in that case. Signed-off-by: Sandra Loosemore <sandra@codesourcery.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20190827223317.8614-1-sandra@codesourcery.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2019-08-28gdbstub: Fix handling of '!' packet with new infraRamiro Polla
Since the '!' packet is not handled by the new infrastructure, gdb_handle_packet() would call run_cmd_parser() with a NULL cmd_parser value, which would lead to an unsupported packet ("$#00") being sent, which could confuse the gdb client. This also has a side-effect of speeding up the initial connection with gdb. Fixes: 3e2c12615b52 ("gdbstub: Implement deatch (D pkt) with new infra") Signed-off-by: Ramiro Polla <ramiro.polla@gmail.com> Message-Id: <20190805190901.14072-1-ramiro.polla@gmail.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2019-08-16sysemu: Split sysemu/runstate.h off sysemu/sysemu.hMarkus Armbruster
sysemu/sysemu.h is a rather unfocused dumping ground for stuff related to the system-emulator. Evidence: * It's included widely: in my "build everything" tree, changing sysemu/sysemu.h still triggers a recompile of some 1100 out of 6600 objects (not counting tests and objects that don't depend on qemu/osdep.h, down from 5400 due to the previous two commits). * It pulls in more than a dozen additional headers. Split stuff related to run state management into its own header sysemu/runstate.h. Touching sysemu/sysemu.h now recompiles some 850 objects. qemu/uuid.h also drops from 1100 to 850, and qapi/qapi-types-run-state.h from 4400 to 4200. Touching new sysemu/runstate.h recompiles some 500 objects. Since I'm touching MAINTAINERS to add sysemu/runstate.h anyway, also add qemu/main-loop.h. Suggested-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20190812052359.30071-30-armbru@redhat.com> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> [Unbreak OS-X build]
2019-07-10gdbstub: revert to previous set_reg behaviourAlex Bennée
The refactoring of handle_set_reg missed the fact we previously had responded with an empty packet when we were not using XML based protocols. This broke the fallback behaviour for architectures that don't have registers defined in QEMU's gdb-xml directory. Revert to the previous behaviour and clean up the commentary for what is going on. Fixes: 62b3320bddd Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Tested-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Cc: Jon Doron <arilou@gmail.com>
2019-07-10gdbstub: add some notes to the header commentAlex Bennée
Add a link to the remote protocol spec and an SPDX tag. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
2019-07-05general: Replace global smp variables with smp machine propertiesLike Xu
Basically, the context could get the MachineState reference via call chains or unrecommended qdev_get_machine() in !CONFIG_USER_ONLY mode. A local variable of the same name would be introduced in the declaration phase out of less effort OR replace it on the spot if it's only used once in the context. No semantic changes. Signed-off-by: Like Xu <like.xu@linux.intel.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Message-Id: <20190518205428.90532-4-like.xu@linux.intel.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2019-06-18monitor: Replace monitor_init() with monitor_init_{hmp, qmp}()Kevin Wolf
Most callers know which monitor type they want to have. Instead of calling monitor_init() with flags that can describe both types of monitors, make monitor_init_{hmp,qmp}() public interfaces that take specific bools instead of flags and call these functions directly. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Message-Id: <20190613153405.24769-15-kwolf@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
2019-06-12gdbstub: Implement qemu physical memory modeJon Doron
Add a new query/set which changes the memory GDB sees to physical memory only. gdb> maint packet qqemu.PhyMemMode will reply the current phy_mem_mode state (1 for enabled, 0 for disabled) gdb> maint packet Qqemu.PhyMemMode:1 Will make GDB read/write only to physical memory, set to 0 to disable Signed-off-by: Jon Doron <arilou@gmail.com> Message-Id: <20190529064148.19856-21-arilou@gmail.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2019-06-12gdbstub: Clear unused variables in gdb_handle_packetJon Doron
Signed-off-by: Jon Doron <arilou@gmail.com> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20190529064148.19856-20-arilou@gmail.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2019-06-12gdbstub: Implement target halted (? pkt) with new infraJon Doron
Note: The user-mode thread-id has been correctly reported since bd88c780e6 Signed-off-by: Jon Doron <arilou@gmail.com> Message-Id: <20190529064148.19856-19-arilou@gmail.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2019-06-12gdbstub: Implement generic set/query (Q/q pkt) with new infraJon Doron
The generic set/query packets contains implementation for varioius sub-commands which are required for GDB and also additional commands which are QEMU specific. To see which QEMU specific commands are available use the command gdb> maintenance packet qqemu.Supported Currently the only implemented QEMU specific command is the command that sets the single step behavior. gdb> maintenance packet qqemu.sstepbits Will display the MASK bits used to control the single stepping. gdb> maintenance packet qqemu.sstep Will display the current value of the mask used when single stepping. gdb> maintenance packet Qqemu.sstep:HEX_VALUE Will change the single step mask. Signed-off-by: Jon Doron <arilou@gmail.com> Message-Id: <20190529064148.19856-18-arilou@gmail.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2019-06-12gdbstub: Implement v commands with new infraJon Doron
Signed-off-by: Jon Doron <arilou@gmail.com> Message-Id: <20190529064148.19856-17-arilou@gmail.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2019-06-12gdbstub: Implement step (s pkt) with new infraJon Doron
Signed-off-by: Jon Doron <arilou@gmail.com> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20190529064148.19856-16-arilou@gmail.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2019-06-12gdbstub: Implement file io (F pkt) with new infraJon Doron
Signed-off-by: Jon Doron <arilou@gmail.com> Message-Id: <20190529064148.19856-15-arilou@gmail.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2019-06-12gdbstub: Implement read all registers (g pkt) with new infraJon Doron
Signed-off-by: Jon Doron <arilou@gmail.com> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20190529064148.19856-14-arilou@gmail.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2019-06-12gdbstub: Implement write all registers (G pkt) with new infraJon Doron
Signed-off-by: Jon Doron <arilou@gmail.com> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20190529064148.19856-13-arilou@gmail.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2019-06-12gdbstub: Implement read memory (m pkt) with new infraJon Doron
Signed-off-by: Jon Doron <arilou@gmail.com> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20190529064148.19856-12-arilou@gmail.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2019-06-12gdbstub: Implement write memory (M pkt) with new infraJon Doron
Signed-off-by: Jon Doron <arilou@gmail.com> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20190529064148.19856-11-arilou@gmail.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2019-06-12gdbstub: Implement get register (p pkt) with new infraJon Doron
Signed-off-by: Jon Doron <arilou@gmail.com> Message-Id: <20190529064148.19856-10-arilou@gmail.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2019-06-12gdbstub: Implement set register (P pkt) with new infraJon Doron
Signed-off-by: Jon Doron <arilou@gmail.com> Message-Id: <20190529064148.19856-9-arilou@gmail.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2019-06-12gdbstub: Implement breakpoint commands (Z/z pkt) with new infraJon Doron
Signed-off-by: Jon Doron <arilou@gmail.com> Message-Id: <20190529064148.19856-8-arilou@gmail.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2019-06-12gdbstub: Implement set_thread (H pkt) with new infraJon Doron
Signed-off-by: Jon Doron <arilou@gmail.com> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20190529064148.19856-7-arilou@gmail.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2019-06-12gdbstub: Implement continue with signal (C pkt) with new infraJon Doron
Signed-off-by: Jon Doron <arilou@gmail.com> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20190529064148.19856-6-arilou@gmail.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2019-06-12gdbstub: Implement continue (c pkt) with new infraJon Doron
Signed-off-by: Jon Doron <arilou@gmail.com> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20190529064148.19856-5-arilou@gmail.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2019-06-12gdbstub: Implement thread_alive (T pkt) with new infraJon Doron
Signed-off-by: Jon Doron <arilou@gmail.com> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20190529064148.19856-4-arilou@gmail.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2019-06-12gdbstub: Implement deatch (D pkt) with new infraJon Doron
Signed-off-by: Jon Doron <arilou@gmail.com> Message-Id: <20190529064148.19856-3-arilou@gmail.com> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2019-06-12gdbstub: Add infrastructure to parse cmd packetsJon Doron
Signed-off-by: Jon Doron <arilou@gmail.com> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20190529064148.19856-2-arilou@gmail.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2019-06-12Include qemu-common.h exactly where neededMarkus Armbruster
No header includes qemu-common.h after this commit, as prescribed by qemu-common.h's file comment. Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20190523143508.25387-5-armbru@redhat.com> [Rebased with conflicts resolved automatically, except for include/hw/arm/xlnx-zynqmp.h hw/arm/nrf51_soc.c hw/arm/msf2-soc.c block/qcow2-refcount.c block/qcow2-cluster.c block/qcow2-cache.c target/arm/cpu.h target/lm32/cpu.h target/m68k/cpu.h target/mips/cpu.h target/moxie/cpu.h target/nios2/cpu.h target/openrisc/cpu.h target/riscv/cpu.h target/tilegx/cpu.h target/tricore/cpu.h target/unicore32/cpu.h target/xtensa/cpu.h; bsd-user/main.c and net/tap-bsd.c fixed up]
2019-06-12Include qemu/module.h where needed, drop it from qemu-common.hMarkus Armbruster
Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20190523143508.25387-4-armbru@redhat.com> [Rebased with conflicts resolved automatically, except for hw/usb/dev-hub.c hw/misc/exynos4210_rng.c hw/misc/bcm2835_rng.c hw/misc/aspeed_scu.c hw/display/virtio-vga.c hw/arm/stm32f205_soc.c; ui/cocoa.m fixed up]
2019-06-11qemu-common: Move qemu_isalnum() etc. to qemu/ctype.hMarkus Armbruster
Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20190523143508.25387-3-armbru@redhat.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
2019-05-28semihosting: move semihosting configuration into its own directoryAlex Bennée
In preparation for having some more common semihosting code let's excise the current config magic from vl.c into its own file. We shall later add more conditionals to the build configurations so we can avoid building this if we don't need it. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
2019-05-22gdbstub: Fix misuse of isxdigit()Markus Armbruster
gdb_read_byte() passes its @ch argument to isxdigit(). Undefined behavior when the value is negative. Two callers: * gdb_chr_receive() passes an uint8_t value. Safe. * gdb_handlesig() a char value. Unsafe. Not a security issue, because the characters come from the gdb client, which is trusted. The obvious fix would be casting @ch to unsigned char. But note that gdb_read_byte() already casts @ch to uint8_t in many places. Uses of @ch without such a cast: (1) Compare to a character constant with == or != (2) s->linesum += ch (3) Store ch or ch ^ 0x20 into s->line_buf[] (4) Check for invalid RLE count: ch < ' ' || ch == '#' || ch == '$' || ch > 126 (5) Pass to isxdigit() (6) Pass to fromhex() Change the parameter type from int to uint8_t, and drop the now redundant casts. Affects the above uses as follows: (1) No change: the character constants are all non-negative. (2) Effectively no change: we only ever use s->linesum & 0xff, and s->linesum is int. (3) No change: s->line_buf[] is char[]. (4) No change. (5) Avoid undefined behavior. (6) No change: only reached when isxdigit(ch) Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20190514180311.16028-5-armbru@redhat.com>
2019-05-22gdbstub: Reject invalid RLE repeat countsMarkus Armbruster
"Debugging with GDB / Appendix E GDB Remote Serial Protocol / Overview" specifies "The printable characters '#' and '$' or with a numeric value greater than 126 must not be used." gdb_read_byte() only rejects values < 32. This is wrong. Impact depends on the caller: * gdb_handlesig() passes a char. Incorrectly accepts '#', '$' and '\127'. * gdb_chr_receive() passes an uint8_t. Additionally accepts characters with the most-significant bit set. Correct the validity check to match the specification. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-Id: <20190514180311.16028-4-armbru@redhat.com>
2019-03-26gdbstub: fix vCont packet handling when no thread is specifiedLuc Michel
The vCont packet accepts a series of actions, each being applied on a given thread ID. Giving no thread ID for an action is valid and means "all threads". This commit fixes vCont packets being incorrectly rejected when no thread ID was given for an action. In multiprocess mode, the GDB Remote Protocol specification is unclear on what "all threads" means. We choose to apply the action on all threads of all attached processes. This commit is based on the initial fix by Lucien Murray-Pitts. Fixes: e40e5204af8388 Reported-by: Lucien Murray-Pitts <lucienmp_antispam@yahoo.com> Reported-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Luc Michel <luc.michel@greensocs.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20190325110452.6756-1-luc.michel@greensocs.com Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2019-02-15gdbstub: Send a reply to the vKill packet.Sandra Loosemore
Per the GDB remote protocol documentation https://sourceware.org/gdb/current/onlinedocs/gdb/Packets.html#index-vKill-packet the debug stub is expected to send a reply to the 'vKill' packet. At least some versions of GDB crash if the gdb stub simply exits without sending a reply. This patch fixes QEMU's gdb stub to conform to the expected behavior. Note that QEMU's existing handling of the legacy 'k' packet is correct: in that case GDB does not expect a reply, and QEMU does not send one. Signed-off-by: Sandra Loosemore <sandra@codesourcery.com> Message-id: 1550008033-26540-1-git-send-email-sandra@codesourcery.com Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2019-02-13char: allow specifying a GMainContext at opening timePaolo Bonzini
This will be needed by vhost-user-test, when each test switches to its own GMainLoop and GMainContext. Otherwise, for a reconnecting socket the initial connection will happen on the default GMainContext, and no one will be listening on it. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Message-Id: <20190202110834.24880-1-pbonzini@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-02-05gdbstub: allow killing QEMU via vKill commandMax Filippov
With multiprocess extensions gdb uses 'vKill' packet instead of 'k' to kill the inferior. Handle 'vKill' the same way 'k' was handled in the presence of single process. Fixes: 7cf48f6752e5 ("gdbstub: add multiprocess support to (f|s)ThreadInfo and ThreadExtraInfo") Cc: Luc Michel <luc.michel@greensocs.com> Signed-off-by: Max Filippov <jcmvbkbc@gmail.com> Reviewed-by: Luc Michel <luc.michel@greensocs.com> Reviewed-by: KONRAD Frederic <frederic.konrad@adacore.com> Tested-by: KONRAD Frederic <frederic.konrad@adacore.com> Message-id: 20190130192403.13754-1-jcmvbkbc@gmail.com Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2019-01-29gdbstub: Simplify gdb_get_cpu_pid() to use cpu->cluster_indexPeter Maydell
Now we're keeping the cluster index in the CPUState, we don't need to jump through hoops in gdb_get_cpu_pid() to find the associated cluster object. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Luc Michel <luc.michel@greensocs.com> Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> Message-id: 20190121152218.9592-5-peter.maydell@linaro.org
2019-01-29gdbstub: fix gdb_get_cpu(s, pid, tid) when pid and/or tid are 0Luc Michel
a TID or PID value means "any thread" (resp. "any process"). This commit fixes the different combinations when at least one value is 0. When both are 0, the function now returns the first attached CPU, instead of the CPU with TID 1, which is not necessarily attached or even existent. When PID is specified but TID is 0, the function returns the first CPU in the process, or NULL if the process does not exist or is not attached. In other cases, it returns the corresponding CPU, while ignoring the PID check when PID is 0. Reported-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Luc Michel <luc.michel@greensocs.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Message-id: 20190119140000.11767-1-luc.michel@greensocs.com Signed-off-by: Peter Maydell <peter.maydell@linaro.org>