From: Tom Tromey <tromey@adacore.com>
To: Pedro Alves <palves@redhat.com>
Cc: Tom Tromey <tromey@adacore.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Instantiate a single source highlighter
Date: Wed, 19 Jun 2019 11:34:00 -0000 [thread overview]
Message-ID: <87muidhkqc.fsf@tromey.com> (raw)
In-Reply-To: <a42f9fe0-28c5-a3f7-c2a9-9dddc071f9c3@redhat.com> (Pedro Alves's message of "Tue, 18 Jun 2019 21:20:02 +0100")
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
>> +/* The global source highlight object, or null if one was never
>> + constructed. This is stored here rather than in the class so that
>> + we don't need to include anything or do conditional compilation in
>> + source-cache.h. */
>> +#ifdef HAVE_SOURCE_HIGHLIGHT
>> +static srchilite::SourceHighlight *highlighter;
>> +#endif
Pedro> Should it be a unique_ptr so that valgrind doesn't complain about
Pedro> it leaking when gdb exits?
Philippe says no, so I didn't make this change.
>> + highlighter->setStyleFile("esc.style");
Pedro> Preexisting, but missing space before parens.
Fixed.
Pedro> To keep the variable's definition and initialization close by,
Pedro> I'd add a get_highlighter function:
I just moved the global to be a static in the block that uses it.
This seemed just as good and avoided more #ifdefs.
Here's what I'm checking in.
Tom
commit ca0c2edb7577c10c3772c8eed8e253971847ccdc
Author: Tom Tromey <tromey@adacore.com>
Date: Tue Jun 18 12:18:24 2019 -0600
Instantiate a single source highlighter
It occurred to me that there's no reason to make a new source
highlighter each time gdb needs to highlight some source code.
Instead, a single one can be created and then simply reused each time.
This patch implements this idea. Tested on x86-64 Fedora 29.
gdb/ChangeLog
2019-06-19 Tom Tromey <tromey@adacore.com>
* source-cache.c (highlighter): New global.
(source_cache::get_source_lines): Create a highlighter on demand.
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 83f47b25701..1aab438d035 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2019-06-19 Tom Tromey <tromey@adacore.com>
+
+ * source-cache.c (highlighter): New global.
+ (source_cache::get_source_lines): Create a highlighter on demand.
+
2019-06-18 Tom de Vries <tdevries@suse.de>
PR gdb/24515
diff --git a/gdb/source-cache.c b/gdb/source-cache.c
index 2d5b549d971..86efe83bf9a 100644
--- a/gdb/source-cache.c
+++ b/gdb/source-cache.c
@@ -197,6 +197,13 @@ source_cache::get_source_lines (struct symtab *s, int first_line,
std::ifstream input (fullname);
if (input.is_open ())
{
+ /* The global source highlight object, or null if one
+ was never constructed. This is stored here rather
+ than in the class so that we don't need to include
+ anything or do conditional compilation in
+ source-cache.h. */
+ static srchilite::SourceHighlight *highlighter;
+
if (s->line_charpos == 0)
{
scoped_fd desc (open_source_file_with_line_charpos (s));
@@ -209,11 +216,15 @@ source_cache::get_source_lines (struct symtab *s, int first_line,
use-after-free. */
fullname = symtab_to_fullname (s);
}
- srchilite::SourceHighlight highlighter ("esc.outlang");
- highlighter.setStyleFile("esc.style");
+
+ if (highlighter == nullptr)
+ {
+ highlighter = new srchilite::SourceHighlight ("esc.outlang");
+ highlighter->setStyleFile ("esc.style");
+ }
std::ostringstream output;
- highlighter.highlight (input, output, lang_name, fullname);
+ highlighter->highlight (input, output, lang_name, fullname);
source_text result = { fullname, output.str () };
m_source_map.push_back (std::move (result));
prev parent reply other threads:[~2019-06-19 11:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-18 19:40 Tom Tromey
2019-06-18 20:00 ` Tom Tromey
2019-06-18 20:20 ` Pedro Alves
2019-06-18 21:25 ` Philippe Waroquiers
2019-06-19 11:34 ` Tom Tromey [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87muidhkqc.fsf@tromey.com \
--to=tromey@adacore.com \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox