aboutsummaryrefslogtreecommitdiff
path: root/src/helper/log.c
AgeCommit message (Collapse)AuthorFilesLines
2022-03-19keep-alive: drop link with log frameworkAntonio Borneo1-20/+16
OpenOCD implements the GDB keep-alive by sending empty strings as output for GDB client. This has been implemented as part of the log framework, creating an odd dependency. Move the keep-alive notifications out of log framework. For the moment, keep keep_alive() inside log.c, but it should be moved in server.c This should also fix an old issue with KDE Konsole when tab alert for activity is enabled. The empty strings is sent to all the connections, including telnet, and causes the tab running OpenOCD telnet to continuously show activity even when no new text is printed. Anyway, I cannot replicate this issue anymore. Change-Id: Iebb00b00fb74b3c9665d9e1ddd3c055275bfbd43 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6840 Reviewed-by: Tomas Vanek <vanekt@fbl.cz> Tested-by: jenkins
2022-03-19log: drop global current_timeAntonio Borneo1-4/+2
The value of this variable is not shared across functions, so the variable can be local. Change-Id: I00b0444209e81c07bb57fb732f47052ad0596728 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6837 Reviewed-by: Tomas Vanek <vanekt@fbl.cz> Tested-by: jenkins
2022-01-22log: fix memory leak when log to file is enabledAntonio Borneo1-0/+9
When log to file is enabled, the file is not closed by OpenOCD at exit. This is reported by Valgrind as a memory leak that is still reachable, as the internal buffers of 'FILE *log_output' are freed by the automatic fclose() at exit. Close the log file before exit. Change-Id: Id472c0d04462035254a9b49ecb0a4037263c6f6f Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6789 Tested-by: jenkins
2021-07-24openocd: remove NULL comparisons with checkpatch [1/2]Antonio Borneo1-2/+2
Patch generated automatically through the new checkpatch with flags "--types COMPARISON_TO_NULL --fix-inplace". This only fixes the comparisons if (symbol == NULL) if (symbol != NULL) The case of NULL on the left side of the comparison is not tested. Some automatic fix is incorrect and has been massaged by hands: - if (*psig == NULL) + if (*!psig) changed as + if (!*psig) Change-Id: If4a1e2b4e547e223532e8e3d9da89bf9cb382ce6 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/6351 Tested-by: jenkins
2021-07-24openocd: fix simple cases of NULL comparisonAntonio Borneo1-7/+7
There are more than 1000 NULL comparisons to be aligned to the coding style. For recurrent NULL comparison it's preferable using trivial scripts in order to minimize the review effort. Patch generated automatically with the command: sed -i PATTERN $(find src/ -type f) where PATTERN is in the list: 's/(\([a-z][a-z0-9_]*\) == NULL)/(!\1)/g' 's/(\([a-z][a-z0-9_]*->[a-z][a-z0-9_]*\) == NULL)/(!\1)/g' 's/(\([a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\) == NULL)/(!\1)/g' 's/(\([a-z][a-z0-9_]*\) != NULL)/(\1)/g' 's/(\([a-z][a-z0-9_]*->[a-z][a-z0-9_]*\) != NULL)/(\1)/g' 's/(\([a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\) != NULL)/(\1)/g' 's/(NULL == \([a-z][a-z0-9_]*\))/(!\1)/g' 's/(NULL == \([a-z][a-z0-9_]*->[a-z][a-z0-9_]*\))/(!\1)/g' 's/(NULL == \([a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\))/(!\1)/g' 's/(NULL != \([a-z][a-z0-9_]*\))/(\1)/g' 's/(NULL != \([a-z][a-z0-9_]*->[a-z][a-z0-9_]*\))/(\1)/g' 's/(NULL != \([a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\))/(\1)/g' Change-Id: Ida103e325d6d0600fb69c0b7a1557ee969db4417 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/6350 Tested-by: jenkins
2021-07-20openocd: manually fix Yoda conditionsAntonio Borneo1-1/+1
Fix the remaining Yoda conditions, detected by checkpatch but not fixed automatically. While there, apply minor style changes. Change-Id: I6e1978b89c4d56a20aceaeb2b52968eb6384432a Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/6356 Tested-by: jenkins Reviewed-by: Oleksij Rempel <linux@rempel-privat.de> Reviewed-by: Xiang W <wxjstz@126.com>
2021-07-02helper: rename camelcase symbolsAntonio Borneo1-4/+4
No cross dependency, just changes internal to each file/function. Change-Id: I16568ddcd8304f5e6748c2e19f32421b047b0357 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/6300 Tested-by: jenkins
2021-06-04gdb_server: Log both incoming and outgoing GDB packetsJan Matyas1-0/+13
- Made sure that also outgoing GDB packets are logged, not only the incoming ones. - Improved the treatment of non-printable characters in the packets to make it more robust. Prior to this change: - Outgoing packets were not printed unless OpenOCD was re-compiled with _DEBUG_GDB_IO_. - Non-prinable characters were only treated in incoming 'X' packets. After this change: - Both incoming and outgoing GDB packets are logged on debug_level >= 3, so that both directions of the GDB channel are visible. - Non-printable characters are checked for in every packet so that hey do not interfere with the terminal. Change-Id: I0613e57ae5059b3279b0abcb71276cf5719a8699 Signed-off-by: Jan Matyas <matyas@codasip.com> Reviewed-on: http://openocd.zylin.com/6269 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2021-05-01Cleanup of config/includes.Tim Newsome1-0/+1
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>
2020-09-05helper: fix minor typosAntonio Borneo1-2/+2
Change-Id: I785e388148c0329e51cb0b39ab30e8ee44f5a7cd Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5801 Tested-by: jenkins
2020-08-16log: handle LOG_*() before calling to log_init()Antonio Borneo1-4/+9
There are cases where LOG_*() functions are called before the logs are initialized with log_init(). E.g. in transport_register() that is executed in gcc constructors, thus called even before main(). With debug_level set to LOG_LVL_USER=-1 all the LOG_ERROR() get dropped. Properly initializing debug_level cause segmentation fault due to log_output still not initialized. Initialize debug_level to LOG_LVL_INFO so errors get printed. Handle separately the case of log_output still NULL, meaning that log_init() is not called yet. Change-Id: I2ea32c87a4955fb44e79b38131c456e25dfbc327 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5602 Tested-by: jenkins
2020-06-06log: fix kept_alive() and report expired timeoutAntonio Borneo1-17/+39
The kept_alive() function is called to inform the keep-alive code that a keep-alive as been just kicked through some other path. But kept_alive() erroneously resets the timeout counter without checking if it has already expired, thus masking a potential timeout. Check if timeout counter has expired during kept_alive(). While there, put the timeout values in macros and explicit the units in the timeout messages. Change-Id: Iaf6368b44e5b5352b1cc4e7efbb2368575dcfa08 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5705 Reviewed-by: <jonatan_zeidler@gmx.de> Tested-by: jenkins
2020-05-09coding style: prototype of functions with no parametersAntonio Borneo1-2/+2
Functions that have no parameters should use "void" as parameter in the function declaration. Issue identified and fixed by script checkpatch from Linux kernel v5.1 using the command find src/ -type f -exec ./tools/scripts/checkpatch.pl \ -q --types FUNCTION_WITHOUT_ARGS --fix-inplace -f {} \; Change-Id: If104ac75b44e939ec86155ff7b5720f2e33c6b39 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5621 Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com> Tested-by: jenkins
2020-02-24log: let command "log_output" to set back its defaultAntonio Borneo1-2/+13
The default log output is stderr. After the command "log_output" has been used to set an output log file, it is possible to return back to stderr only on *NIX hosts specifying a new log output file as "/dev/stderr", but this is not intuitive, not documented and not portable out of *NIX. Make command "log_output" able to set back the default output to stderr when the parameter is either "default" or is missing. While there, add debug message to log the change and make the command return error on incorrect syntax. Change-Id: I8c7c929780f58e2c23936737c8e7274a96734786 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5233 Tested-by: jenkins Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2020-01-02jtag_vpi: multiple improvementsJan Matyas1-0/+25
- Fix: Proper handling of read_socket() and write_socket() in case of "partial" read/write. - Added low-level JTAG IO debug capability (_DEBUG_JTAG_IO_) - Zero-fill packet buffers, avoid sending pieces of uninitialized memory over the network (memset struct vpi_cmd) - Use close_socket() instead of close() - needed for Win32 - Fixed usage messages of jtag_vpi_command_handlers Change-Id: I8bd19bc5c9512fe8e798600212e8a95213f50f5b Signed-off-by: Jan Matyas <matyas@codasip.com> Reviewed-on: http://openocd.zylin.com/5177 Tested-by: jenkins Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com> Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-05-14helper/command: change prototype of command_print/command_print_samelineAntonio Borneo1-1/+1
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-07log: add const qualifier to commands structAntonio Borneo1-1/+1
The struct log_command_handlers[] is never modified. Add const qualifier to it. Change-Id: I5785aeb09ae9c23eaf7c34a05b88d0c7285f2d78 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5009 Reviewed-by: Tomas Vanek <vanekt@fbl.cz> Tested-by: jenkins
2018-12-11helper/log: remove dead code in log_forward()Antonio Borneo1-38/+8
Commit f1be0e6af2e204805a8bc2e8cadf828b9fa46c98 ("HELPER/LOG: review unused symbols") removed a set of unused functions and, as consequence, there is no code anymore that sets the variable "log_forward_count". But, the commit above did not removed the code (now dead) that depends on "log_forward_count" set. Remove the code dependant on "log_forward_count" set and the variable itself. Change-Id: I6efe93d1dccbe13c409c5bc55ba47a2684c0e3ac Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/4779 Tested-by: jenkins Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2017-10-03Fix typo in comment.Tim Newsome1-1/+1
Change-Id: I6567f85f399315e1dac98881765dfaa6eab5facb Signed-off-by: Tim Newsome <tim@sifive.com> Reviewed-on: http://openocd.zylin.com/4238 Tested-by: jenkins Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2017-08-10log: Add a new debug level (4) for verbose I/O debugAndreas Fritiofson1-5/+7
Change ftdi SWD driver and CMSIS-DAP to use it instead of LOG_DEBUG(). Change-Id: I17ba3de2086c7159209db61fba3faf067dfc5023 Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com> Reviewed-on: http://openocd.zylin.com/3805 Tested-by: jenkins Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2017-04-23help/log.c: better error handling for "log_output"Girts1-3/+9
* Close previous log file if one was opened before. * Return error if opening file fails. Change-Id: I103025cd86bcac785fe39e13bc7d5f79d78e38e7 Signed-off-by: Girts Folkmanis <opensource@girts.me> Reviewed-on: http://openocd.zylin.com/3878 Tested-by: jenkins Reviewed-by: Freddie Chopin <freddie.chopin@gmail.com>
2016-10-07helper/log: Add log_vprintf_lf()Marc Schink1-14/+25
Add log_vprintf_lf() to enable the possibility to output log messages with a variable argument list. Change-Id: I7fd6e93db63a7d98f662df2881a42e4d923c3848 Signed-off-by: Marc Schink <openocd-dev@marcschink.de> Reviewed-on: http://openocd.zylin.com/3709 Tested-by: jenkins Reviewed-by: Andreas Färber <afaerber@suse.de> Reviewed-by: Paul Fertser <fercerpav@gmail.com>
2016-07-19Fix usage of timeval_ms()Andreas Färber1-7/+7
First, fix the timeval_ms() implementation to not have K&R but ANSI argument semantics by adding a missing void. timeval_ms() returns an int64_t, not uint64_t or long long. Consistently use int64_t for variables and PRI*64 as format string. While at it, change a few related variables to bool for clarity. Note that timeval_ms() may return a negative error code, but not a single caller checks for that. Change-Id: I27cf83e75b3e9a8913f6c43e98a281bea77aac13 Signed-off-by: Andreas Färber <afaerber@suse.de> Reviewed-on: http://openocd.zylin.com/3499 Tested-by: jenkins Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com> Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2016-05-24Remove FSF address from GPL noticesMarc Schink1-3/+1
Also make GPL notices consistent according to: https://www.gnu.org/licenses/gpl-howto.html Change-Id: I84c9df40a774958a7ed91460c5d931cfab9f45ba Signed-off-by: Marc Schink <openocd-dev@marcschink.de> Reviewed-on: http://openocd.zylin.com/3488 Tested-by: jenkins Reviewed-by: Andreas Färber <afaerber@suse.de> Reviewed-by: Freddie Chopin <freddie.chopin@gmail.com> Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
2015-11-03helper/log: Cleanup #includes.Marc Schink1-2/+2
Change-Id: Ie343524dd843d518086a86866391b5a34556082b Signed-off-by: Marc Schink <openocd-dev@marcschink.de> Reviewed-on: http://openocd.zylin.com/2996 Tested-by: jenkins Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2014-10-06helper: constify log_stringsSpencer Oliver1-1/+1
Change-Id: I5bdd8958e79b754d56bb7aee2892856e557eed76 Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk> Reviewed-on: http://openocd.zylin.com/2296 Tested-by: jenkins
2013-06-05update files to correct FSF addressSpencer Oliver1-1/+1
Change-Id: I429f7fd51f77b0e7c86d7a7f110ca31afd76c173 Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk> Reviewed-on: http://openocd.zylin.com/1426 Tested-by: jenkins Reviewed-by: Paul Fertser <fercerpav@gmail.com>
2012-07-27Test the incoming debug_level, rather than the current.Alan Bowman1-1/+1
The existing code tests the current debug_level for validity, allowing the user to set it too high and never change it after that. The new behaviour is to test the debug_level that the user has requested. Change-Id: I85726a2e606c8d137e9b1cfe76fee865084844b1 Signed-off-by: Alan Bowman <alan.michael.bowman@gmail.com> Reviewed-on: http://openocd.zylin.com/764 Tested-by: jenkins Reviewed-by: Øyvind Harboe <oyvindharboe@gmail.com>
2012-02-06build: cleanup src/helper directorySpencer Oliver1-92/+76
Change-Id: I71a312df783995e9083c345c25e73902d5aef59e Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk> Reviewed-on: http://openocd.zylin.com/415 Tested-by: jenkins
2012-01-04retire ERROR_INVALID_ARGUMENTS and replace with ERROR_COMMAND_SYNTAX_ERRORØyvind Harboe1-2/+2
Change-Id: I6dee51e1fab1944085391f274a343cdb9014c7a4 Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com> Reviewed-on: http://openocd.zylin.com/300 Tested-by: jenkins Reviewed-by: Øyvind Harboe <oyvindharboe@gmail.com> Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2011-02-25log: debug level is between silent and debug output levelsØyvind Harboe1-9/+8
It wasn't previously possible to silence the output. Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
2010-10-01log: remove hack to redirect logs when pipes are in useØyvind Harboe1-17/+2
There is an explicit command "log_output" that can be used to redirect log output to a file, no need for a hack in the first place. Before enabling pipes, use "log_output foo" to redirect log output to the "foo" files. Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
2010-05-18jim: fix bug in tcl "puts"Øyvind Harboe1-9/+4
tcl "puts" didn't work because the logging code sensored strings that did not include a '\n'. The correct thing is to sensor empty strings, which are used to keep gdb connection alive. The tcl "puts" code broke apart strings which do contain '\n' in order to implement the -nonewline argument, which is how it got hurt by the bug in log.c Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
2010-04-10HELPER/LOG: review unused symbolsAntonio Borneo1-38/+0
Remove unused functions: - log_catch - log_rethrow - log_try Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
2010-01-09src/helper: usage/help updatesDavid Brownell1-8/+13
Make "usage" messages use the same EBNF as the User's Guide; no angle brackets. Improve and correct various helptexts. Don't use "&function"; a function's name is its address. Fix some whitespace glitches, shrink a few overlong lines. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
2009-12-03change #include "server.h" to <server/server.h>Zachary T Welch1-1/+1
Changes from the flat namespace to heirarchical one. Instead of writing: #include "server.h" the following form should be used. #include <server/server.h> The exception is from .c files in the same directory.
2009-11-25support OPENOCD_DEBUG_LEVEL environment settingZachary T Welch1-0/+13
Detect the OPENOCD_DEBUG_LEVEL setting in log_init(), allowing the very early startup phases to be debugged.
2009-11-25log: improve initializationZachary T Welch1-8/+3
Removes redundant assignment of start_ms from log_register_commands(). Eliminates command_context parameter and return value. Adds Doxygen comment block for this API call.
2009-11-24log: use register_commands()Zachary T Welch1-5/+19
Use register_commands() for logging callbacks. Improve help and add proper usage.
2009-11-24use COMMAND_REGISTER macroZachary T Welch1-2/+2
Replaces direct calls to register_command() with a macro, to allow its parameters to be changed and callers updated in phases.
2009-11-24improve alloc_vprintfAndreas Fritiofson1-27/+16
The previous implementation was unnecessarily complex. Get rid of the loops, let vsnprintf() tell us directly how much storage we need and allocate that. A second pass writes the actual string. Also add a va_end() that was missing. This should be much faster for large strings and less wasteful for small ones. A quirk that has been retained is that some callers patch in a newline at the end of the returned string and depend on alloc_vprintf to allocate at least one byte extra. Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com> Signed-off-by: Zachary T Welch <zw@superlucidity.net>
2009-11-17command_handler: change 'cmd_ctx' to CMD_CTXZachary T Welch1-1/+1
Convert all command handler 'cmd_ctx' parameter usage with CMD_CTX.
2009-11-17command_handler: change 'args' to CMD_ARGVZachary T Welch1-2/+2
This patch converts all instances of 'args' in COMMAND_HANDLER routines to use CMD_ARGV macro.
2009-11-17command_handler: change to 'argc' to CMD_ARGCZachary T Welch1-3/+3
This patch converts all instances of 'argc' in COMMAND_HANDLER routines to use CMD_ARGC.
2009-11-16helper/log: improve API parameter typesZachary T Welch1-15/+12
Uses unsigned type to pass line numbers. Use uint64_t to pass sleep routines their milliseconds. Updates sleep routines to use this type and improve whitespace.
2009-11-16target: less implicit inclusion of "command.h"David Brownell1-1/+0
Lots of files still include it, often through needless duplicate inclusion of "log.h"; sigh. This cleans up the inclusion graph a bunch, so there are fewer inclusion paths, but it doesn't change much otherwise. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
2009-11-13command_context_t -> struct command_contextZachary T Welch1-3/+3
Remove misleading typedef and redundant suffix from struct command_context.
2009-11-13log_callback_t -> struct log_callbackZachary T Welch1-5/+5
Removes useless and confusing typedef for log callback structure. Types with _t should be suitable for passing by-value as arguments.
2009-11-13use COMMAND_HANDLER macro to define all commandsZachary T Welch1-2/+2
2009-11-05Improve debug_level command argument parsing.Zachary T Welch1-3/+1