aboutsummaryrefslogtreecommitdiff
path: root/src/server
AgeCommit message (Collapse)AuthorFilesLines
2021-05-15server: gdb_server: Add colon for target extended-remoteYasushi SHOJI1-1/+1
Both GDB commands "target remote" and "target extended-remote" require to have ":" right before port number. e.g. (gdb) target extended-remote :3333 Add ":" to the warning message so that users can copy & past it. Change-Id: Id6d8ec1e4dfd3c12cb7f3b314064f2c35fa7ab55 Signed-off-by: Yasushi SHOJI <yashi@spacecubics.com> Reviewed-on: http://openocd.zylin.com/6237 Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com> Tested-by: jenkins Reviewed-by: Marc Schink <dev@zapb.de> Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2021-05-08Add IPDBG JtagHost functionality to OpenOCDDaniel Anselmi3-1/+796
IPDBG are utilities to debug IP-cores. It uses JTAG for transport to/from the FPGA. The different UIs use TCP/IP as transport. The JtagHost makes the bridge between these two. Comparable to the bridge between GDB and the in-circuit- debugging-unit of a micro controller. Change-Id: Ib1bc10dcbd4ea426e492bb7b2d85c1ed1b7a8d5a Signed-off-by: Daniel Anselmi <danselmi@gmx.ch> Reviewed-on: http://openocd.zylin.com/5938 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2021-05-08telnet/auto-complete: hide deprecated and internal commandsAntonio Borneo1-0/+3
For both: - TCL proc that redirect deprecated commands to the new commands, - TCL proc used internally and not supposed to be exposed to user, add their name to the list of commands that should be hide by the telnet auto-complete. Change-Id: I05237c6a79334b7d2b151dfb129fb57b2f40bba6 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/6195 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
2021-05-08telnet: allow hiding selected commands during auto-completionAntonio Borneo2-1/+18
We have TCL procedure and commands that we do not want to show in the list of auto-completion. E.g. TCL wrappers for deprecated commands, internal procedures that are not supposed to be exposed to user, or even commands that the user decides to hide. Create a TCL procedure to be called by telnet auto-complete code in place of the hard-coded TCL command. The procedure will run the same command and will filter-out the unwanted command names. Initialize the list of commands to be filtered-out with the name of the TCL procedure above, as it is considered as internal. Change-Id: I2d83bbf8194502368c589c85cccb617e69128c69 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/6194 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
2021-05-01Cleanup of config/includes.Tim Newsome2-0/+2
Remove a use of AH_BOTTOM from configure.ac. This macro is used by autoheader to add '#include' of some include file to the end of config.h.in and then to config.h. OpenOCD can be built with a custom config.h, so it's preferable to move these '#include' statement directly in the C files that need them dropping this unneeded dependency. It also causes problems when I want to use the gnulib library (which comes with its own Makefile, and does not have the same include path as the top-level Makefile). So this change touches a lot of files, but is actually really simple. It does not affect functionality at all. Change-Id: I52c70bf15eb2edc1dd10e0fde23b2bcd4caec000 Signed-off-by: Tim Newsome <tim@sifive.com> Reviewed-on: http://openocd.zylin.com/6171 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2021-05-01telnet: auto-completion of "registered" commandsTarek BOCHKATI1-25/+223
auto-completion behavior: - if there is only one matched command complete the user-command - else if multiple matches add the common part then in second step list all matched commands - sub-commands are handled in the same way - auto-completion restarts after these characters ';', '[', '{' Change-Id: I1b81dd19191a5785e68d0bb5cd244e01a4dd0587 Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com> Reviewed-on: http://openocd.zylin.com/6095 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2021-04-11target/aarch64: Add watchpoint supportLiming Sun1-1/+1
There are some breakpoint/watchpoint related code in armv8_dpm.c, but seems not working for aarch64. Target aarch64 has its own breakpoint implementation in aarch64.c. This commit follows the same logic to add watchpoint support for target aarch64. This commit also increases the size of stop_reason[] in function gdb_signal_reply() since the old size is too small to fit in a 64-bit address, such as ffff8000115e6980. Change-Id: I907dc0e648130e36b434220f570c37d0e8eb5ce1 Signed-off-by: Liming Sun <lsun@mellanox.com> Signed-off-by: Daniel Goehring <dgoehrin@os.amperecomputing.com> Reviewed-on: http://openocd.zylin.com/4761 Tested-by: jenkins Reviewed-by: Liming Sun <limings@nvidia.com> Reviewed-by: Kevin Burke <kevinb@os.amperecomputing.com> Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de> Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2021-03-19telnet: support end and home keysTarek BOCHKATI1-0/+6
this will help navigate to the line start and end easily Change-Id: I3f42eb5267df64c59a85ece67de5fce39a8843ec Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com> Reviewed-on: http://openocd.zylin.com/6094 Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com> Tested-by: jenkins
2021-03-10server: revert commit 7e6556b3cad8Antonio Borneo6-11/+6
With the removal of old tpiu code, commit 7e6556b3cad8 ("server: permit the add_service function to return the created service") http://openocd.zylin.com/5717/ can be reverted. Fix also the new calls to add_service(). Change-Id: Ib7f2dfc6a9e829239e20313e0f121911085fdc00 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/6031 Tested-by: jenkins Reviewed-by: Adrian M Negreanu <adrian.negreanu@nxp.com>
2020-12-26gdb_server: fix HW thread status at gdb attachAntonio Borneo1-9/+9
At gdb attach, the event TARGET_EVENT_GDB_ATTACH is in charge of halting the target. For HW thread, rtos_update_threads() should be called after the event to detect and record the new 'halted' status. Instead it is called immediately before the event, thus reading the status before the halt. Move after the event the call to rtos_update_threads(). Change-Id: Iab3480ea0f5283ed6580f0f6c11200083197d1e9 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5983 Tested-by: jenkins
2020-12-26gdb_server: minor fix for indentationAntonio Borneo1-1/+1
Use a TAB in place of 4 spaces Change-Id: Ic34b7c3ef24078d2c36a193d4dd079bca5a7ef2e Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Fixes: a4cdce0129a6 ("gdb_server: prevent false positive valgrind report") Reviewed-on: http://openocd.zylin.com/5982 Tested-by: jenkins Reviewed-by: Jonathan McDowell <noodles-openocd@earth.li>
2020-12-02Add initial RTT supportMarc Schink3-1/+220
Real Time Transfer (RTT) is an interface specified by SEGGER based on basic memory reads and writes to transfer data bidirectionally between target and host. Every target that supports so called "background memory access", which means that the target memory can be accessed by the debugger while the target is running, can be used. RTT is especially of interest for targets which do not support Serial Wire Output (SWO) (e.g. ARM Cortex-M0) or where using semihosting is not possible (e.g. real-time applications) [1]. The data transfer is organized in channels where each channel consists of an up- and/or down-channel. See [2] for more details. Channels are exposed via TCP connections. One or more RTT server can be assigned to each channel to make them accessible to an unlimited number of TCP connections. The current implementation does not respect buffer flags which are used to determine what happens when writing to a full buffer. Note that the implementation is designed in a way that the RTT operations can be directly performed by an adapter (e.g. J-Link). [1] https://devzone.nordicsemi.com/tutorials/6/ [2] https://www.segger.com/jlink-rtt.html Change-Id: I8bc8a1b381fb74e08b8752d5cf53804cc573c1e0 Signed-off-by: Marc Schink <dev@zapb.de> Reviewed-on: http://openocd.zylin.com/4055 Tested-by: jenkins Reviewed-by: Tomas Vanek <vanekt@fbl.cz> Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2020-11-15target, register: allow a register hidden from gdb and 'reg' cmdTomas Vanek1-4/+4
Introduce a 'hidden' flag in struct reg to support a register cache containing different views of same data: e.g. Cortex-M has primask, basepri, faultmask and control registers accessed as one word. With the hidden flag we can add an reg_list item corresponding to hw access without exposing the register to user level. All the struct reg are allocated with calloc() but one in xscale.c allocated by malloc(). Change this one to use calloc() as well to guarantee initial value hidden=false Change-Id: I8da9f5a5a60777ae7ef943a841307487bd80fc6f Signed-off-by: Tomas Vanek <vanekt@fbl.cz> Reviewed-on: http://openocd.zylin.com/5325 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com> Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2020-11-07server: permit the add_service function to return the created serviceTarek BOCHKATI5-5/+10
returning the created service seems useful: as the only method to get the freshly created service is by getting the last item in the services linked list, and this seems to be like an intrusion to service internal mechanism. possibly, we could get the service from a connection but this is possible only from [new_connection|input|connection_closed]_handler_t, but this is not always practical: example: armv7m: add a TCP channel to stream captured trace http://openocd.zylin.com/#/c/5345/ here we poll for trace and broadcast to all connections outside of these xxx_handler_t functions also, storing one of the connections in new_connection_handler_t and get the service from it is possible, but this will make the code less readable. Change-Id: I5fef1baecec1e054953c6faf5b99d864ecc97f02 Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com> Reviewed-on: http://openocd.zylin.com/5717 Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com> Tested-by: jenkins
2020-11-04server: declare local functions as staticAntonio Borneo1-1/+1
Functions that are not used outside the file should be declared as static. Change-Id: I57b2fa6e49e87e14604bd34c4f1d2f037f401507 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5897 Tested-by: jenkins Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2020-11-04gdb_server: allow multiple GDB connections to selected targetsAntonio Borneo1-1/+1
The default way of working is to have a single GDB attached to one target, so OpenOCD accepts only one connection to the GDB port of each targets and rejects any further connection. There are some barely safe use cases in which it could get useful having a second GDB connection to the same target. One such use case is while using GDB as a 'non-intrusive memory inspector', as explained in the OpenOCD documentation. One GDB can be left running an infinite loop to dump some memory area, or even analysing the content, while keeping a second GDB ready for user interaction or spot memory check. Add a target configure option to specify the maximum number of GDB connections allowed for that target, keeping the default to 1. Change-Id: I4985a602e61588df0b527d2f2aa5b955c93e125e Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5865 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
2020-11-04gdb_server: fix clang static analyzer warningTomas Vanek1-1/+1
Warning: line 373, column 15 Assigned value is garbage or undefined Most probably a false warning, building the hex string byte per byte seems too complicated for static analyze. Change malloc to calloc to silence the warning. Change-Id: I746d43fa51abf05582ccf2680ed72dc557798a7a Signed-off-by: Tomas Vanek <vanekt@fbl.cz> Reviewed-on: http://openocd.zylin.com/5905 Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com> Tested-by: jenkins Reviewed-by: Jonathan McDowell <noodles-openocd@earth.li>
2020-10-24server/telnet: Handle Ctrl+KBrian Brooks1-1/+11
Handle Ctrl+K shortcut which clears the line from the cursor position to the end of line. Change-Id: I2ecff5284473cef7c11cf9cb7e1c0c97d55f6c1c Signed-off-by: Brian Brooks <brooks.brian@gmail.com> Reviewed-on: http://openocd.zylin.com/5868 Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com> Tested-by: jenkins Reviewed-by: Marc Schink <dev@zapb.de>
2020-09-05openocd: use proper format with uint32_tAntonio Borneo1-9/+9
Modify the format strings to properly handle uint32_t data types. Change-Id: I4de49bf02c9e37b72240224c23fc83abe8a4fa83 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5819 Tested-by: jenkins
2020-09-05openocd: avoid checking for non NULL pointer to free itAntonio Borneo3-32/+14
The function free() can be called with a NULL pointer as argument, no need to check the argument before. If the pointer is NULL, no operation is performed by free(). Remove the occurrences of pattern: if (ptr) free(ptr); While there replace a sequence malloc(size)+memset(,0,size) with a calloc(1,size). Replace a pointer assignment to '0' with an assignment to NULL. In server/*, an error is logged if the ptr was already NULL. This cannot happen since the pointer was already referenced few lines before and openocd would have been already SIGSEGV in that case, so remove the log. Change-Id: I10822029fe8390b59edff4070575bf7f754e44ac Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5808 Reviewed-by: Adrian M Negreanu <adrian.negreanu@nxp.com> Tested-by: jenkins
2020-08-16server/gdb_server: fix incorrect condition checkChristopher Head1-1/+1
The warning message should be printed if the target is NOT halted, not if it IS halted. Change-Id: I0a38292a8a2e20e4a4a5ada92b475d551d4cbf38 Signed-off-by: Christopher Head <chead@zaber.com> Reviewed-on: http://openocd.zylin.com/5794 Reviewed-by: Tomas Vanek <vanekt@fbl.cz> Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2020-08-08gdb_server: refuse gdb connection if target is not examinedAntonio Borneo1-0/+11
If the target is not examined, many internal data required for the gdb connections are not ready nor allocated. This causes OpenOCD to hit a segmentation fault. After the execution of the gdb-attach event handler, check if target has been examined and eventually return error to refuse the gdb connection. Plus, since OpenOCD does not implements non-stop mode yet, gdb expects the target to be halted by the inferior when the connection is established. Print a warning to inform the user in case the target is not halted, but still accept the gdb connection to permit the non-intrusive memory inspection with gdb, as explained in http://openocd.org/doc/html/GDB-and-OpenOCD.html#gdbmeminspect Change-Id: If727d68f683c3a94e4826e8c62977de41274ceff Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5201 Tested-by: jenkins
2020-07-26server: fix minor typosAntonio Borneo2-4/+4
Change-Id: Ibf835dc174a1a160ec0d57000a113c35f2713045 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5760 Tested-by: jenkins
2020-07-08gdb_server: suggest user to prefer GDB extended modeAntonio Borneo1-0/+7
In case of GDB connection not using extended mode, issue a warning message to suggest the user to switch using the extended mode. Issue the message only once at each run of OpenOCD, to avoid too much noise. Update the documentation to suggest using extended mode. Change-Id: I9326e84f748d5d7912d5a48f00f0fb541ca19221 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5311 Tested-by: jenkins Reviewed-by: Karl Palsson <karlp@tweak.net.au>
2020-07-08coding style: add arguments to function prototypesAntonio Borneo1-1/+1
Issue identified by checkpatch script from Linux kernel v5.1 using the command find src/ -type f -exec ./tools/scripts/checkpatch.pl \ -q --types FUNCTION_ARGUMENTS -f {} \; This patch also fixes an incorrect function prototype in zy1000.c. ZY1000 minidriver implementation overrides the function arm11_run_instr_data_to_core_noack_inner(), but the prototype is not the same as in src/target/arm11_dbgtap.c and to avoid compile error it was changed also the prototype of the called function arm11_run_instr_data_to_core_noack_inner_default(). Change-Id: I476cda8cdb0e1e280795b3b43ca95c40d09e4a3d Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5630 Tested-by: jenkins Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
2020-07-07flash/nor: Use proper data types in driver APIMarc Schink1-9/+6
Use 'unsigned int' and 'bool' instead of 'int' where appropriate. While at it, fix some coding style issues. No new Clang analyzer warnings. Change-Id: I700802c9ee81c3c7ae73108f0f8f06b15a4345f8 Signed-off-by: Marc Schink <dev@zapb.de> Reviewed-on: http://openocd.zylin.com/4929 Tested-by: jenkins Reviewed-by: Tomas Vanek <vanekt@fbl.cz> Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2020-06-14openocd: fix issue in WIN32 with TCP adaptersTarek BOCHKATI2-2/+18
Issue: server_quit is called before adapter_quit: In WIN32 only in server_quit we do an WSACleanup, which terminates/closes all active sockets. So if the adapter is TCP based, the adapter.quit handler will fail if it will need to send some commands through TCP. Example: close_socket in jtag_vpi_quit will fail in WIN32 because the socket is already closed and the errno is set as "Bad File Descriptor" To fix that we introduced new functions called server_host_os_entry/quit to manage specific OS setup (hence WSA for sockets in WINDOWS) in order to delay WSACleanup after adapter_quit(). Change-Id: Ie4afacafe123857f6ae300e376bdfcf0d8c027ac Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com> Reviewed-on: http://openocd.zylin.com/5456 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2020-05-09coding style: avoid unnecessary line continuationsAntonio Borneo1-4/+4
Line continuation, adding a backslash as last char of the line, is requested in multi-line macro definition, but is not necessary in the rest of C code. Remove it where present. Identified by checkpatch script from Linux kernel v5.1 using the command find src/ -type f -exec ./tools/scripts/checkpatch.pl \ -q --types LINE_CONTINUATIONS -f {} \; Change-Id: Id0c69e93456731717a7b290b16580e9f8ae741bc Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5619 Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com> Tested-by: jenkins
2020-05-09server/telnet: Fix history outputMarc Schink1-15/+35
Restore the prompt after the "history" command is invoked. Change-Id: I3d0744abbc58e82b039e06f21675efa180e8e1b0 Signed-off-by: Marc Schink <openocd-dev@marcschink.de> Reviewed-on: http://openocd.zylin.com/3414 Tested-by: jenkins Reviewed-by: Marc Schink <dev@zapb.de> Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2020-05-02server: set tcp port and bind address before initAntonio Borneo4-4/+4
All the servers open the listening socket during openocd "init"; it's not possible to change the tcp port or the bind address after "init". In current code, the call order during "init" permits to change the port and bind address of tcl and telnet server if the related command is issued after "init" in the same script or on openocd command line. This is not guaranteed to work if the call order during "init" changes, so it's incorrect. Change the commands "bindto" and "*_port" to COMMAND_CONFIG. Change-Id: Id88f225a67a872b4bcaf3b799466bddedc248015 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reported-by: Christopher Head <chead@zaber.com> Fixes: https://sourceforge.net/p/openocd/tickets/264/ Reviewed-on: http://openocd.zylin.com/5595 Reviewed-by: Christopher Head <chead@zaber.com> Tested-by: jenkins
2020-04-13server: set connection::input_pending type to boolTarek BOCHKATI3-6/+6
Change-Id: Ifae8ac2761a7a8fa12732b71c2de456e7558bd2b Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com> Reviewed-on: http://openocd.zylin.com/5565 Tested-by: jenkins Reviewed-by: Marc Schink <dev@zapb.de>
2020-04-13server/gdb_server: set gdb_connection::ctrl_c type to boolTarek BOCHKATI1-6/+6
Change-Id: I828b83b181f7a222ee2e6cb67eb337c6cd8712ac Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com> Reviewed-on: http://openocd.zylin.com/5566 Tested-by: jenkins Reviewed-by: Marc Schink <dev@zapb.de>
2020-04-12gdb_server: print the target associated to the gdb portAntonio Borneo1-1/+1
While running OpenOCD on multi-target SoC, it's not immediate to detect which target is associated to each GDB port. The log only reports: Info : Listening on port 3333 for gdb connections and a verbose debug log is required to get such info. Promote to LOG_INFO() the existing debug message that already reports the association, obtaining for each port: Info : starting gdb server for stm32mp15x.cpu0 on 3333 Info : Listening on port 3333 for gdb connections Change-Id: I1bd75655a3449222c959e6e82f5e0f8f5acd908a Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5525 Tested-by: jenkins Reviewed-by: Jan Matyas <matyas@codasip.com> Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
2020-02-24coding style: fix space around pointer's asteriskAntonio Borneo1-1/+1
The script checkpatch available in new Linux kernel offers an experimental feature for automatically fix the code in place. While still experimental, the feature works quite well for simple fixes, like spacing. This patch has been created automatically with the script under review for inclusion in OpenOCD, using the command find src/ -type f -exec ./tools/scripts/checkpatch.pl \ -q --types POINTER_LOCATION --fix-inplace -f {} \; then manually reviewed. OpenOCD coding style does not mention the space around pointer's asterisk, so no check is enforced. This patch only makes the style uniform across the files. The patch only changes amount and position of whitespace, thus the following commands show empty diff git diff -w git log -w -p git log -w --stat Change-Id: Iefb4998e69bebdfe0d1ae65cadfc8d2c4f166d13 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5197 Tested-by: jenkins
2020-01-16server/server: fix clang static analyzer warningTomas Vanek1-1/+1
Change-Id: I317e189b62540e3688a20d88a95f551280317f14 Signed-off-by: Tomas Vanek <vanekt@fbl.cz> Reviewed-on: http://openocd.zylin.com/5373 Tested-by: jenkins Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
2019-12-19gdb_server: fix extended_protocol for multi-targetAntonio Borneo1-4/+5
The flag extended_protocol is currently a single static variable thus, in case of multiple targets, it is shared among all the gdb connections. This is an issue if the gdb connections are not all using extended protocol, but also when one connection get closed because the code sets the flag to zero impacting the other connections still open. Move the flag extended_protocol in the per-connection struct gdb_connection. Change-Id: I19d565f925df6a31767fd8d392242f60867109f2 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5310 Tested-by: jenkins Reviewed-by: Moritz Fischer <moritzf@google.com> Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-12-19gdb_server: fix string length with semihosting_fileioAntonio Borneo1-5/+5
The GDB file-I/O remote protocol extension, used for implementing the semihosting file I/O, requires the length of strings to include the trailing zero character, as explicitly stated inside a comment in GDB source code [1]: /* 1. Parameter: Ptr to pathname / length incl. trailing zero. */ ARM specification for semihosting [2] requires the string length to not include the trailing zero character, e.g. in SYS_OPEN specifications: "field 3: An integer that gives the length of the string pointed to by field 1. The length does not include the terminating null character that must be present." The mismatch above requires OpenOCD to add "one" to the string length before passing it to GDB. Such conversion is missing either in the generic semihosting provider of the data, the function semihosting_common(), and in the consumer of the data, the gdb_server function gdb_fileio_reply(). The conversion is already implemented in the target specific function nds32_get_gdb_fileio_info(), but it's not the preferred place for such GDB specific requirement. This issue affects the semihosting calls "open", "unlink", "rename" and "system". Remove the "+1" conversion from nds32_get_gdb_fileio_info(). Add the "+1" conversion in gdb_fileio_reply(). [1] http://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;f=gdb/remote-fileio.c;h=11c141e42c4d#l381 [2] "Semihosting for AArch32 and AArch64, Release 2.0" https://static.docs.arm.com/100863/0200/semihosting.pdf Change-Id: I35461bcb30f734fe2d51f7f0d418e3d04b4af506 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5322 Tested-by: jenkins Reviewed-by: Steven Stallion <sstallion@gmail.com> Reviewed-by: Muhammad Omair Javaid <omair.javaid@linaro.org> Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-12-12server/tcl_server.c: Fix buffer overrunJimmy1-1/+1
The input buffer size is checked only after writing past its end. Change-Id: I6a9651c5b7d82efe338468d67bf6caca41004b01 Signed-off-by: Jimmy <nhminus@gmail.com> Reviewed-on: http://openocd.zylin.com/5352 Tested-by: jenkins Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-12-10server: gdb_server: fix memory map generation on a 32-bit BE hostPaul Fertser1-5/+5
Due to lack of printf format check wrong specifier was used and it actually broke operation on a 32-bit BE host. So fix this and add the necessary function attributes so that the bugs like that can be uncovered automaticaly. Reported and pinpointed by Karl Palsson on IRC. Change-Id: I254ec28fcd9bb30594d607f74a6dba5456c2c7a1 Tested-by: Karl Palsson <karlp@tweak.net.au> Signed-off-by: Paul Fertser <fercerpav@gmail.com> Reviewed-on: http://openocd.zylin.com/5342 Tested-by: jenkins Reviewed-by: Karl Palsson <karlp@tweak.net.au> Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2019-11-22CVE-2018-5704: Prevent some forms of Cross Protocol Scripting attacksAndreas Fritiofson1-0/+11
OpenOCD can be targeted by a Cross Protocol Scripting attack from a web browser running malicious code, such as the following PoC: var x = new XMLHttpRequest(); x.open("POST", "http://127.0.0.1:4444", true); x.send("exec xcalc\r\n"); This mitigation should provide some protection from browser-based attacks and is based on the corresponding fix in Redis: https://github.com/antirez/redis/blob/8075572207b5aebb1385c4f233f5302544439325/src/networking.c#L1758 Change-Id: Ia96ebe19b74b5805dc228bf7364c7971a90a4581 Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com> Reported-by: Josef Gajdusek <atx@atx.name> Reviewed-on: http://openocd.zylin.com/4335 Tested-by: jenkins Reviewed-by: Jonathan McDowell <noodles-openocd@earth.li> Reviewed-by: Paul Fertser <fercerpav@gmail.com>
2019-10-18gdb_server: Support vRun packet, allow setting cmdline from GDBAndreas Fritiofson1-8/+102
GDB uses the vRun packet if available to restart a running process in extended remote mode. Support this like the R packet and set the semihosting command-line to allow it to be specified from GDB. Change-Id: I9cb812b22170630f782113c9927e46e0cd5b1f0f Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com> Reviewed-on: http://openocd.zylin.com/5186 Tested-by: jenkins Reviewed-by: Tomas Vanek <vanekt@fbl.cz> Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
2019-10-18gdb-server: Create arch-specific structure type for every featureAlexey Brodkin1-4/+4
As it is mentioned here [1] type's ID is unique name within containing feature. That said if regs of the same type located in different features it's required to insert type definition at least in each feature. See more details in discussion here [2]. [1] https://sourceware.org/gdb/onlinedocs/gdb/Target-Description-Format.html#Types [2] https://github.com/foss-for-synopsys-dwc-arc-processors/openocd/commit/2a5f5125ac8fa0e1359b6be03b209f9f5d1ade82#r33460077 Change-Id: Id92b061cfbf47d5c032a02c2c406b28affd0b02a Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com> Reviewed-on: http://openocd.zylin.com/5179 Tested-by: jenkins Reviewed-by: Muhammad Omair Javaid <omair.javaid@linaro.org> Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
2019-08-28gdb_server, rtos: Fine-grained RTOS register accessTim Newsome1-35/+46
1. Add get_thread_reg() to rtos. It's used in rtos_get_gdb_reg() to read the value of a single register, instead of reading all register values by calling get_thread_reg_list(). 2. Add set_reg() to rtos. gdb_server uses this to change a single register value for a specific thread. 3. Add target_get_gdb_reg_list_noread() so it's possible for gdb to get a list of registers without attempting to read their contents. The clang static checker doesn't find any new problems with this change. Change-Id: I77f792d1238cb015b91527ca8cb99593ccc8870e Signed-off-by: Tim Newsome <tim@sifive.com> Reviewed-on: http://openocd.zylin.com/5114 Tested-by: jenkins Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
2019-06-06gdb_server: remove call to jtag_execute_queue()Antonio Borneo1-6/+0
In the initial commit 6c9b804d6187edda4f46f8458deec0b17ec76bb9 in 2007's svn://svn.berlios.de/openocd/trunk@246 a target script gdb_program_config was called before gdb flash programming. To guarantee the script does not left any pending command in the jtag queue, a call to jtag_execute_queue() was inserted after the execution of the script. In following commit ef1cfb23947bd32798077c6abb5c25a049460ae9 in 2008's svn://svn.berlios.de/openocd/trunk@975 the script was replaced by the event "old-gdb_program_config" and the call to jtag_execute_queue() get executed in every case, even if the event handler was not present. At last, commit bb3793c9a4ccd232c4ee3ce0a36bf200589ca0bb ("target: remove legacy target events") stripped away the obsolete event but left the call to jtag_execute_queue(), now completely useless. Remove the call to jtag_execute_queue() and clean-up the code around it. Change-Id: I284f54d656d431ad6cdc25ca18218c09db31bd25 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/4911 Tested-by: jenkins Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-06-04gdb_server: fix GDB_BUFFER_SIZE usage, fix unaligned access during bulk ↵Bohdan Tymkiv1-6/+4
transfers Currently size of the GDB buffer is 16384 bytes but it is treated as nul-terminated string in most of the code, so effective size of the buffer is actually 16383 bytes. OpenOCD responds with `PacketSize=3fff` to qSupported request. Result of GDB's `m` command is encoded in hex so each data byte uses two bytes in the buffer. As a result GDB will split bulk read requests into chunks 0x1fff bytes each. This causes troubles on targets (or memory regions) which support only aligned, word-sized access (such as MMIO buffers). Steps to reproduce (psoc6 target): gdb> dump binary memory dump.bin 0x040320000 (0x040320000 + 65536) OpenOCD: Error: Failed to read memory at 0x40321ffe Error: Failed to read memory at 0x40321000 Error: Failed to read memory at 0x40323000 Error: Failed to read memory at 0x40325ffe Error: Failed to read memory at 0x40329ffa Error: Failed to read memory at 0x40329ffc Error: Failed to read memory at 0x4032bffc Error: Failed to read memory at 0x4032dffa Consolidate GDB_BUFFER_SIZE usage: ensure size of each buffer is (GDB_BUFFER_SIZE + 1), add explicit comment that additional byte is used for nul-termination. Report correct size of the buffer to GDB (0x4000) as recommended in GDB's docummentation: `if the stub stores packets in a NUL-terminated format, it should allow an extra byte in its buffer for the NUL` Checked with clang-asan, clang-analyzer, valgrind - no new errors. Change-Id: I909e8a2c6b010c5d4a304641808d4a807a4ec18d Signed-off-by: Bohdan Tymkiv <bhdt@cypress.com> Reviewed-on: http://openocd.zylin.com/5109 Tested-by: jenkins Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-05-14helper/command: change prototype of command_print/command_print_samelineAntonio Borneo2-4/+4
To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should switch to CMD as first parameter. Change prototype of command_print() and command_print_sameline() to pass CMD instead of CMD_CTX. Since the first parameter is currently not used, the change can be done though scripts without manual coding. This patch is created using the command: sed -i PATTERN $(find src/ doc/ -type f) with all the following patters: 's/\(command_print(cmd\)->ctx,/\1,/' 's/\(command_print(CMD\)_CTX,/\1,/' 's/\(command_print(struct command_\)context \*context,/\1invocation *cmd,/' 's/\(command_print_sameline(cmd\)->ctx,/\1,/' 's/\(command_print_sameline(CMD\)_CTX,/\1,/' 's/\(command_print_sameline(struct command_\)context \*context,/\1invocation *cmd,/' This change is inspired by http://openocd.zylin.com/1815 from Paul Fertser but is now done through scripting. Change-Id: I3386d8f96cdc477e7a2308dd18269de3bed04385 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Signed-off-by: Paul Fertser <fercerpav@gmail.com> Reviewed-on: http://openocd.zylin.com/5081 Tested-by: jenkins Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-04-07Set empty usage field for commands that do not need parametersAntonio Borneo1-0/+1
The missing field causes runtime debug message BUG: command '%s' does not have the '.usage' field filled out While there, fix some minor typo in the help messages: s/deasert/deassert/ s/Deasert/Deassert/ Change-Id: If3dd18265cda103ca0d05609f67f4ca58e7cbb27 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5024 Tested-by: jenkins Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-04-03tcl_server: fix minor typo in commentPeter Lawrence1-1/+1
ctrl-z usage is incorrectly commented as ctrl-d Change-Id: I54fe1775760ee984154bbae380baa38bcaffa04e Signed-off-by: Peter Lawrence <majbthrd@gmail.com> Reviewed-on: http://openocd.zylin.com/4863 Tested-by: jenkins Reviewed-by: Christopher Head <chead@zaber.com> Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-03-08gdb_server, target: Add target_address_bits()Tim Newsome1-5/+4
Targets can use this to expose how many address bits there are. gdb_server uses this to send gdb the appropriate upper limit in the memory-map. (Before this change the upper limit would only be correct for 32-bit targets.) Change-Id: Idb0933255ed53951fcfb05e040674bcdf19441e1 Signed-off-by: Tim Newsome <tim@sifive.com> Reviewed-on: http://openocd.zylin.com/4947 Tested-by: jenkins Reviewed-by: Peter Mamonov <pmamonov@gmail.com> Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-03-06gdb_server: fix 'null' pointer passed as 'nonnull' parameterAntonio Borneo1-2/+2
The null pointer used as second parameter to gdb_put_packet() is passed as second parameter to the memcpy() in line 408 of gdb_put_packet_inner(). In this case memcpy() does not segfault because also the parameter length is zero. Nevertheless, the prototype of memcpy() requires a nonnull pointer. Fixed by passing an empty string in place of the null pointer. Issue highlighted by clang 7.0.0 with warning message: "Null pointer passed as an argument to a 'nonnull' parameter" Change-Id: Ib3dde95d76fcc5fb245ee2d6669e5535d0e0b127 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/4946 Tested-by: jenkins Reviewed-by: Tomas Vanek <vanekt@fbl.cz>