Use safe-ctype.h (ISSPACE etc.) in symbol parsing & comparison
authorPedro Alves <palves@redhat.com>
Sat, 23 May 2020 11:46:37 +0000 (12:46 +0100)
committerPedro Alves <palves@redhat.com>
Sat, 23 May 2020 11:46:37 +0000 (12:46 +0100)
commit51e2cfa2dc2dd600727c91701c747c28fa67a5df
tree5b3affafd078666406b81aab732e84be1cd58c36
parentc892b44730bb1a66d614fd47fabe47555ca83b3b
Use safe-ctype.h (ISSPACE etc.) in symbol parsing & comparison

This patch avoids depending on the current locale when parsing &
comparing symbol names, by using libiberty's safe-ctype.h uppercase
TOLOWER, ISXDIGIT, etc. macros instead of the standard ctype.h
tolower, isxdigit, etc. macros/functions.

This commit:

 commit b1b60145aedb8adcb0b9dcf43a5ae735c2f03b51
 Author:     Pedro Alves <palves@redhat.com>
 AuthorDate: Tue May 22 17:35:38 2018 +0100

    Support UTF-8 identifiers in C/C++ expressions (PR gdb/22973)

did something similar, except in the expression parser.

This can improve GDB's symbol loading performance significantly.
Currently strcmp_iw_ordered can show up high on profiles (called from
sort_pst_symbols -> std::sort) because of the isspace and tolower
functions.  Hannes mentions seeing it as high as in ~24% of the
profiling samples on Windows
(https://sourceware.org/pipermail/gdb-patches/2020-May/168858.html).

I tested GDB's performance (built with "-g -O2") loading a "-g -O0"
build of gdb.

I ran GDB 10 times like:

  /bin/time -f %e \
    ./gdb/gdb --data-directory ./gdb/data-directory -nx \
    -batch /tmp/gdb-g-O0

Then I computed the mean time.

The baseline mean time was

 gdb    2.515

This patch brings the number down to

 gdb    2.096

Which is an around 16% improvement.

gdb/ChangeLog:
2020-05-23  Pedro Alves  <palves@redhat.com>

* utils.c: Include "gdbsupport/gdb-safe-ctype.h".
(parse_escape): Use ISDIGIT instead of isdigit.
(puts_debug): Use gdb_isprint instead of isprint.
(fprintf_symbol_filtered): Use ISALNUM instead of isalnum.
(cp_skip_operator_token, skip_ws, strncmp_iw_with_mode): Use
ISSPACE instead of isspace.
(strncmp_iw_with_mode): Use TOLOWER instead of tolower and ISSPACE
instead of isspace.
(strcmp_iw_ordered): Use ISSPACE instead of isspace.
(string_to_core_addr): Use TOLOWER instead of tolower, ISXDIGIT
instead of isxdigit and ISDIGIT instead of isdigit.

gdbsupport/ChangeLog:
2020-05-23  Pedro Alves  <palves@redhat.com>

* gdb-safe-ctype.h: New.
gdb/ChangeLog
gdb/utils.c
gdbserver/ChangeLog
gdbsupport/gdb-safe-ctype.h [new file with mode: 0644]
This page took 0.025573 seconds and 4 git commands to generate.