summaryrefslogtreecommitdiff
path: root/gdbsupport/common-utils.cc
Commit message (Collapse)AuthorAgeFilesLines
* gdb: Fix building with latest libc++Manoj Gupta2023-04-291-1/+1
| | | | | | | | | | | | | | | | Latest libc++[1] causes transitive include to <locale> when <mutex> or <thread> header is included. This causes gdb to not build[2] since <locale> defines isupper/islower etc. functions that are explicitly macroed-out in safe-ctype.h to prevent their use. Use the suggestion from libc++ to include <locale> internally when building in C++ mode to avoid build errors. Use safe-gdb-ctype.h as the include instead of "safe-ctype.h" to keep this isolated to gdb since rest of binutils does not seem to use much C++. [1]: https://reviews.llvm.org/D144331 [2]: https://issuetracker.google.com/issues/277967395
* gdb: move displaced_step_dump_bytes into gdbsupport (and rename)Andrew Burgess2023-03-291-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | It was pointed out during review of another patch that the function displaced_step_dump_bytes really isn't specific to displaced stepping, and should really get a more generic name and move into gdbsupport/. This commit does just that. The function is renamed to bytes_to_string and is moved into gdbsupport/common-utils.{cc,h}. The function implementation doesn't really change. Much... ... I have updated the function to take an array view, which makes it slightly easier to call in a couple of places where we already have a gdb::bytes_vector. I've then added an inline wrapper to convert a raw pointer and length into an array view, which is used in places where we don't easily have a gdb::bytes_vector (or similar). Updated all users of displaced_step_dump_bytes. There should be no user visible changes after this commit. Finally, I ended up having to add an include of gdb_assert.h into array-view.h. When I include array-view.h into common-utils.h I ran into build problems because array-view.h calls gdb_assert. Approved-By: Simon Marchi <simon.marchi@efficios.com>
* Update copyright year range in header of all files managed by GDBJoel Brobecker2023-01-011-1/+1
| | | | | | | This commit is the result of running the gdb/copyright.py script, which automated the update of the copyright year range for all source files managed by the GDB project to be updated to include year 2023.
* internal_error: remove need to pass __FILE__/__LINE__Pedro Alves2022-10-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, every internal_error call must be passed __FILE__/__LINE__ explicitly, like: internal_error (__FILE__, __LINE__, "foo %d", var); The need to pass in explicit __FILE__/__LINE__ is there probably because the function predates widespread and portable variadic macros availability. We can use variadic macros nowadays, and in fact, we already use them in several places, including the related gdb_assert_not_reached. So this patch renames the internal_error function to something else, and then reimplements internal_error as a variadic macro that expands __FILE__/__LINE__ itself. The result is that we now should call internal_error like so: internal_error ("foo %d", var); Likewise for internal_warning. The patch adjusts all calls sites. 99% of the adjustments were done with a perl/sed script. The non-mechanical changes are in gdbsupport/errors.h, gdbsupport/gdb_assert.h, and gdb/gdbarch.py. Approved-By: Simon Marchi <simon.marchi@efficios.com> Change-Id: Ia6f372c11550ca876829e8fd85048f4502bdcf06
* Automatic Copyright Year update after running gdb/copyright.pyJoel Brobecker2022-01-011-1/+1
| | | | | | | | This commit brings all the changes made by running gdb/copyright.py as per GDB's Start of New Year Procedure. For the avoidance of doubt, all changes in this commits were performed by the script.
* gdb: introduce target_waitkind_str, use it in target_waitstatus::to_stringSimon Marchi2021-11-221-2/+6
| | | | | | | | | | | | | | | | | | I would like to print target_waitkind values in debug messages, so I think that a target_waitkind-to-string function would be useful. While at it, use it in target_waitstatus::to_string. This changes the output of target_waitstatus::to_string a bit, but I think it is for the better. The debug messages will show a string matching exactly the target_waitkind enumerator (minus the TARGET_WAITKIND prefix). As a convenience, make string_appendf return the same reference to string it got as a parameter. This allows doing this: return string_appendf (str, "foo"); ... keeping the code concise. Change-Id: I383dffc9c78614e7d0668b1516073905e798eef7
* gdb/gdbsupport: make xstrprintf and xstrvprintf return a unique_ptrAndrew Burgess2021-11-161-5/+4
| | | | | | | | The motivation is to reduce the number of places where unmanaged pointers are returned from allocation type routines. All of the callers are updated. There should be no user visible changes after this commit.
* gdbsupport: move xfree into its own fileAndrew Burgess2021-11-161-0/+1
| | | | | | | | | | | | | | | | In the next commit I'd like to reference gdb_unique_ptr within the common-utils.h file. However, this requires that I include gdb_unique_ptr.h, which requires that xfree be defined. Interestingly, gdb_unique_ptr.h doesn't actually include anything that defines xfree, but I was finding that when I added a gdb_unique_ptr.h include to common-utils.h I was getting a dependency cycle; before my change xfree was defined when gdb_unique_ptr.h was processed, while after my change it was not, and this made g++ unhappy. To break this cycle, I propose to move xfree into its own header file, gdb-xfree.h, which I'll then include into gdb_unique_ptr.h and common-utils.cc.
* New memory-tag commandsLuis Machado2021-03-241-0/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add new commands under the "memory-tag" prefix to allow users to inspect, modify and check memory tags in different ways. The available subcommands are the following: - memory-tag print-logical-tag <expression>: Prints the logical tag for a particular address. - memory-tag withltag <expression> <tag>: Prints the address tagged with the logical tag <tag>. - memory-tag print-allocation-tag <expression>: Prints the allocation tag for a particular address. - memory-tag setatag <expression> <length> <tags>: Sets one or more allocation tags to the specified tags. - memory-tag check <expression>: Checks if the logical tag in <address> matches its allocation tag. These commands make use of the memory tagging gdbarch methods, and are still available, but disabled, when memory tagging is not supported by the architecture. I've pondered about a way to make these commands invisible when memory tagging is not available, but given the check is at runtime (and support may come and go based on a process' configuration), that is a bit too late in the process to either not include the commands or get rid of them. Ideas are welcome. gdb/ChangeLog: 2021-03-24 Luis Machado <luis.machado@linaro.org> * printcmd.c: Include gdbsupport/rsp-low.h. (memory_tag_list): New static global. (process_print_command_args): Factored out of print_command_1. (print_command_1): Use process_print_command_args. (show_addr_not_tagged, show_memory_tagging_unsupported) (memory_tag_command, memory_tag_print_tag_command) (memory_tag_print_logical_tag_command) (memory_tag_print_allocation_tag_command, parse_with_logical_tag_input) (memory_tag_with_logical_tag_command, parse_set_allocation_tag_input) (memory_tag_set_allocation_tag_command, memory_tag_check_command): New functions. (_initialize_printcmd): Add "memory-tag" prefix and subcommands. gdbsupport/ChangeLog: 2021-03-24 Luis Machado <luis.machado@linaro.org> * rsp-low.cc (fromhex, hex2bin): Move to ... * common-utils.cc: ... here. (fromhex) Change error message text to not be RSP-specific. * rsp-low.h (fromhex, hex2bin): Move to ... * common-utils.h: ... here.
* Update copyright year range in all GDB filesJoel Brobecker2021-01-011-1/+1
| | | | | | | | | This commits the result of running gdb/copyright.py as per our Start of New Year procedure... gdb/ChangeLog Update copyright year range in copyright header of all GDB files.
* gdbsupport: make use of safe-ctype functions from libibertyAndrew Burgess2020-12-111-11/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Make use of the safe-ctype replacements for the standard ctype character checking functions in gdbsupport/common-utils.cc. The gdbsupport library is included into both gdb and gdbserver, and on the gdbserver side there are two targets, gdbserver itself, and also libinproctrace.so. libiberty was already being included in the gdbserver link command, but was missing from the libinproctrace.so link. As a result, after changing gdbsupport/common-utils.cc to depend on libiberty, libinproctrace.so would no longer link until I modified its link line. gdbserver/ChangeLog: * Makefile.in (IPA_LIB): Include libiberty library. gdbsupport/ChangeLog: * gdbsupport/common-utils.cc: Change 'ctype.h' include to 'safe-ctype.h'. (extract_string_maybe_quoted): Use safe-ctype function versions. (is_digit_in_base): Likewise. (digit_to_int): Likewise. (strtoulst): Likewise. (skip_spaces): Likewise. (skip_to_space): Likewise.
* gdbsupport: Drop now unused function 'stringify_argv'Michael Weghorn2020-05-251-23/+0
| | | | | | | | | | | | | The function did not properly escape special characters and all uses have been replaced in previous commits, so drop the now unused function. gdbsupport/ChangeLog: * common-utils.cc, common-utils.h (stringify_argv): Drop now unused function stringify_argv Change-Id: Id5f861f44eae1f0fbde3476a5eac23a842ed04fc
* gdbsupport: rename source files to .ccSimon Marchi2020-02-131-0/+417
This patch renames the .c source files in gdbsupport to .cc. In the gdb directory, there is an argument against renaming the source files, which is that it makes using some git commands more difficult to do archeology. Some commands have some kind of "follow" option that makes git try to follow renames, but it doesn't work in all situations. Given that we have just moved the gdbsupport directory, that argument doesn't hold for source files in that directory. I therefore suggest renaming them to .cc, so that they are automatically recognized as C++ by various tools and editors. The original motivation behind this is that when building gdbsupport with clang, I get: CC agent.o clang: error: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Werror,-Wdeprecated] In the gdb/ directory, we make clang happy by passing "-x c++". We could do this in gdbsupport too, but I think that renaming the files is a better long-term solution. gdbserver still does its own build of gdbsupport, so a few changes in its Makefile are necessary. gdbsupport/ChangeLog: * Makefile.am: Rename source files from .c to .cc. (CC, CFLAGS): Don't override. (AM_CFLAGS): Rename to ... (AM_CXXFLAGS): ... this. * Makefile.in: Re-generate. * %.c: Rename to %.cc. gdbserver/ChangeLog: * Makefile.in: Rename gdbsupport source files from .c to .cc.