* Which language when parsing a breakpoint condition?
@ 2003-09-05 23:24 Joel Brobecker
2003-09-05 23:28 ` Joel Brobecker
0 siblings, 1 reply; 3+ messages in thread
From: Joel Brobecker @ 2003-09-05 23:24 UTC (permalink / raw)
To: gdb
A friend of mine just asked this question: When you have a multilanguage
application (say Ada and C), if the current language is auto,c and you
place a conditional breakpoint inside Ada code, which language should be
used to parse and evaluate the condition? Ada or C.
Intuitevely, I would have say: the Ada parser, since we will be in an
Ada function when the breakpoint exception is evaluated. However, GDB
currently uses the parser of the language that is current at the time
when the user sets the condition (either with the "if" keyword of the
"break" command, or when using the "condition" command). So GDB
currently uses the C parser. Shouldn't it be the opposite?
Looking at the code, I think it is fairly easy to change the behavior
to be:
1. If the language is auto, then:
a. Determine the language associated to the code where the breakpoint
is set, and use it to parse and evaluate the condition
b. If unable to determine the language, then use the current language.
2. If the language mode is not auto, then: use the current language.
If the langauge is auto, then use the language associated to
the code where the breakpoint is set - if unable to determine the
language, then use the current langauge.
Use the language associated to the code where the breakpoint
is set to evaluate the
language_auto????
Looking at parse_exp_1: I think we can provide the other behavior by
replacing the following call...
if (current_language->la_parser ())
... by something like this:
struct language_defn *lang = NULL;
if (language_mode == language_auto)
{
/* Find the language associated to the context block.
Default to the current language if it can not be determined. */
struct symbol *func = block_function (expression_context_block);
if (func != NULL)
lang = language_def (SYMBOL_LANGUAGE (func));
if (lang == NULL)
lang = current_language;
}
else
{
/* Use the current language to parse the string. */
lang = current_language;
}
/* Parse the string. */
if (lang->la_parser ())
Sounds reasonable?
--
Joel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Which language when parsing a breakpoint condition?
2003-09-05 23:24 Which language when parsing a breakpoint condition? Joel Brobecker
@ 2003-09-05 23:28 ` Joel Brobecker
2003-09-08 19:36 ` Jim Blandy
0 siblings, 1 reply; 3+ messages in thread
From: Joel Brobecker @ 2003-09-05 23:28 UTC (permalink / raw)
To: gdb
[ARGH! Sorry, my first mail was not finished when I sent it. I wanted
to postpone it, and accidentally sent it instead. Here is the message
I meant to send.]
A friend of mine just asked this question: When you have a multilanguage
application (say Ada and C), if the current language is auto,c and you
place a conditional breakpoint inside Ada code, which language should be
used to parse and evaluate the condition? Ada or C.
Intuitevely, I would have say: the Ada parser, since we will be in an
Ada function when the breakpoint exception is evaluated. However, GDB
currently uses the parser of the language that is current at the time
when the user sets the condition (either with the "if" keyword of the
"break" command, or when using the "condition" command). So GDB
currently uses the C parser. Shouldn't it be the opposite?
Looking at the code, I think it is fairly easy to change the behavior
to be:
1. If the language is auto, then:
a. Determine the language associated to the code where the breakpoint
is set, and use it to parse and evaluate the condition
b. If unable to determine the language, then use the current language.
2. If the language mode is not auto, then: use the current language.
We should be covering all cases by making changing the following line
in parse_exp_1...
if (current_language->la_parser ())
... by something like this:
struct language_defn *lang = NULL;
if (language_mode == language_auto)
{
/* Find the language associated to the context block.
Default to the current language if it can not be determined. */
struct symbol *func = block_function (expression_context_block);
if (func != NULL)
lang = language_def (SYMBOL_LANGUAGE (func));
if (lang == NULL)
lang = current_language;
}
else
{
/* Use the current language to parse the string. */
lang = current_language;
}
/* Parse the string. */
if (lang->la_parser ())
Sounds reasonable?
--
Joel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Which language when parsing a breakpoint condition?
2003-09-05 23:28 ` Joel Brobecker
@ 2003-09-08 19:36 ` Jim Blandy
0 siblings, 0 replies; 3+ messages in thread
From: Jim Blandy @ 2003-09-08 19:36 UTC (permalink / raw)
To: Joel Brobecker; +Cc: gdb
You're absolutely right. When the language mode is auto, it's silly
to parse an expression in the context of a particular block, but in a
language other than the one the block in written in.
Your code looks like the right idea to me, too. Some notes:
- expout->language_defn needs to be set correctly, too, doesn't it?
- Since get_selected_block can return zero, you'll need to deal with
the case where expression_context_block is zero.
You can linearize the cases like this, I think:
if (language_mode == language_manual)
lang = current_language
else if (expression_context_block)
set lang from that, with block_function and language_def
else
lang = current_language
At least, I think this makes it clearer that every case is covered.
Up to you.
(This sort of issue comes up a lot in relation to conditional
breakpoints, since I think it's one of the few cases where an
expression is ever parsed/evaluated in a scope other than that of the
selected frame. Checking watchpoints is a similar case.)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-09-08 19:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-05 23:24 Which language when parsing a breakpoint condition? Joel Brobecker
2003-09-05 23:28 ` Joel Brobecker
2003-09-08 19:36 ` Jim Blandy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox