aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorZENG Hao <c@cyano.cn>2025-04-19 06:41:28 +0800
committerTom Tromey <tromey@adacore.com>2025-04-22 08:46:00 -0600
commitdadaf42c653f4eba6ada9d09d087253e8c97ecd7 (patch)
treef674910d0c39182089e2d3c8b428afaa591ce028 /gdb
parent236fb2b56e6367159aa5457d99428a751ff37cdd (diff)
downloadbinutils-dadaf42c653f4eba6ada9d09d087253e8c97ecd7.zip
binutils-dadaf42c653f4eba6ada9d09d087253e8c97ecd7.tar.gz
binutils-dadaf42c653f4eba6ada9d09d087253e8c97ecd7.tar.bz2
gdb: fix ui-style regex initializing order
This fixes a crash on Windows NT 4.0, where windows-nat failed dynamic loading some Win32 functions and print a warning message with styled string, which depends on ui-style regex. By using `compiled_regex` constructor, the regex is guaranteed to be initialized before `_initialize_xxx` functions. Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ui-style.c17
1 files changed, 4 insertions, 13 deletions
diff --git a/gdb/ui-style.c b/gdb/ui-style.c
index b8321c5..b8d73ab 100644
--- a/gdb/ui-style.c
+++ b/gdb/ui-style.c
@@ -45,7 +45,8 @@ static const char ansi_regex_text[] =
/* The compiled form of ansi_regex_text. */
-static regex_t ansi_regex;
+static compiled_regex ansi_regex (ansi_regex_text, REG_EXTENDED,
+ _("Error in ANSI terminal escape sequences regex"));
/* This maps 8-color palette to RGB triples. The values come from
plain linux terminal. */
@@ -364,7 +365,7 @@ ui_file_style::parse (const char *buf, size_t *n_read)
{
regmatch_t subexps[NUM_SUBEXPRESSIONS];
- int match = regexec (&ansi_regex, buf, ARRAY_SIZE (subexps), subexps, 0);
+ int match = ansi_regex.exec (buf, ARRAY_SIZE (subexps), subexps, 0);
if (match == REG_NOMATCH)
{
*n_read = 0;
@@ -531,7 +532,7 @@ skip_ansi_escape (const char *buf, int *n_read)
{
regmatch_t subexps[NUM_SUBEXPRESSIONS];
- int match = regexec (&ansi_regex, buf, ARRAY_SIZE (subexps), subexps, 0);
+ int match = ansi_regex.exec (buf, ARRAY_SIZE (subexps), subexps, 0);
if (match == REG_NOMATCH || buf[subexps[FINAL_SUBEXP].rm_so] != 'm')
return false;
@@ -539,16 +540,6 @@ skip_ansi_escape (const char *buf, int *n_read)
return true;
}
-void _initialize_ui_style ();
-void
-_initialize_ui_style ()
-{
- int code = regcomp (&ansi_regex, ansi_regex_text, REG_EXTENDED);
- /* If the regular expression was incorrect, it was a programming
- error. */
- gdb_assert (code == 0);
-}
-
/* See ui-style.h. */
const std::vector<color_space> &