Re: [PATCH v2 2/2] mi-out: Implement mi redirection using a stack.

Pedro Alves
2014-07-31T16:23:24Z

Awesome! Thanks for doing this.

This is close. Some notes on the technicalities below.

On 07/31/2014 04:08 PM, Adrian Sendroiu wrote:
> +# This triggers a nested mi_ui_out redirection, by disabling a breakpoint
> +# inside a python command that has to_string = True.
> +if ![mi_skip_python_tests] {
> + mi_gdb_test "-break-insert do_nothing" ".*"
> + mi_gdb_test "-break-commands 2 \"python gdb.execute('disable 2', True, True)\"" ".*"

It's better to use $bpnum instead of hardcoding 2, as otherwise if someone adds a
test that adds another breakpoint before this, this test stops being
effective, silently.

> +
> + mi_gdb_test "-exec-continue" ".*"

This should use mi_send_resuming_command/mi_expect_stop
or mi_execute_to, so that the test works when the whole MI
testsuite is run in async mode.

> +
> + set s [string repeat "A" 100]
> +
> + # This will crash gdb if redirection is not done properly.
> + mi_gdb_test "echo $s" ".*\\^done" "mi nested redirect"

In addition to that, it'd be good to confirm the breakpoint did
end up disabled, which likewise confirms the breakpoint command
was set on the breakpoint we wanted. (might not need the "echo"
if that itself already causes a crash.)

> +proc mi_skip_python_tests {} {
> + global mi_gdb_prompt
> + global gdb_py_is_py3k
> + global gdb_py_is_py24
> +
> + gdb_test_multiple "python print ('test')" "verify python support" {
> + -re "not supported.*$mi_gdb_prompt$" {
> + unsupported "Python support is disabled."
> + return 1
> + }
> + -re "$mi_gdb_prompt$" {}
> + }
> +
> + set gdb_py_is_py24 0
> + gdb_test_multiple "python print (sys.version_info\[0\])" "check if python 3" {
> + -re "3.*$mi_gdb_prompt$" {
> + set gdb_py_is_py3k 1
> + }
> + -re ".*$mi_gdb_prompt$" {
> + set gdb_py_is_py3k 0
> + }
> +
> + }
> + if { $gdb_py_is_py3k == 0 } {
> + gdb_test_multiple "python print (sys.version_info\[1\])" "check if python 2.4" {
> + -re "\[45\].*$mi_gdb_prompt$" {
> + set gdb_py_is_py24 1
> + }
> + -re ".*$mi_gdb_prompt$" {
> + set gdb_py_is_py24 0
> + }
> + }
> + }
> +
> + return 0
> +}

I think that we can avoid this duplication by renaming
skip_python_tests, adding it a prompt_re parameter, and
using that instead of $gdb_prompt. Something like:

proc skip_python_tests {} {
skip_python_tests_prompt "$gdb_prompt $"
}

proc mi_skip_python_tests {
skip_python_tests_prompt "$mi_gdb_prompt$"
}

Did you try that?

Thanks,
Pedro Alves