diff --git a/scripts/menu.pl b/scripts/menu.pl index adb77a0..10963d0 100644 --- a/scripts/menu.pl +++ b/scripts/menu.pl @@ -33,6 +33,7 @@ my $local_db_conf = "$local_root/db.conf"; my $resultbrowser_port = '5000'; my $resultbrowser = 'resultbrowser.py'; +my $qemu_gdb_port = '9000'; my $remote_root = '/home/lab/smchurla/Documents/failnix'; my $remote_builds_dir = "$remote_root/builds"; @@ -521,13 +522,46 @@ my %handlers = ( die "No build selected" unless @selected_builds; my $selected_build = $selected_builds[0]; - my $build_dir = "$local_builds_dir/$selected_build"; - my $build_name = $selected_build =~ s/.*?_.*?_(.*?)_.*$/$1/r; + my $build_dir = "$local_builds_dir/$selected_build"; + my $build_name = $selected_build =~ s/.*?_.*?_(.*?)_.*$/$1/r; + my $is_baremetal = $selected_build =~ /linux-baremetal$/; + my $is_wasm = $build_name eq 'aot' || $build_name eq 'interp'; say "$build_name"; - system( - 'gdb', + # Baremetal builds boot the iso in qemu and attach gdb + my $qemu_pid; + if ($is_baremetal) { + say "Forking..."; + $qemu_pid = fork(); + die "fork failed: $!\n" unless defined $qemu_pid; + + if ( $qemu_pid == 0 ) { + + # child -> qemu. + exec( + 'qemu-system-i386', + '-drive', + "file=$build_dir/system.iso,media=cdrom", + '-boot', + 'd', + '-m', + '32', + '-D', + "$local_root/qemu.log", + '-d', + "int,cpu_reset", + '-no-reboot', + '-no-shutdown', + '-S', + '-gdb', + "tcp::$qemu_gdb_port", + ) or die "failed to exec qemu: $!\n"; + } + } + + # Shared gdb args + my @gdb_args = ( '--tui', '-q', "$build_dir/system.elf", @@ -537,29 +571,52 @@ my %handlers = ( "set substitute-path 'build-$build_name' '$build_dir'", '-ex', "set substitute-path '/build/source/core' '$local_wamr/core'", - '-ex', - 'break main', - '-ex', - 'break fail_start_trace', - '-ex', - 'break fail_stop_trace', - '-ex', - 'break fail_marker_positive', - '-ex', - 'break fail_marker_detected', - '-ex', - 'break fail_marker_negative', - '-ex', - 'break fail_marker_group1', - '-ex', - 'break os_mmap', - '-ex', - 'break wamr_malloc', - '-ex', - 'break wamr_realloc', - '-ex', - 'break wamr_free', ); + + # Specific gdb args + if ($is_baremetal) { + push @gdb_args, + '-ex', "target remote localhost:$qemu_gdb_port", + '-ex', 'break os_main'; + } + else { + push @gdb_args, '-ex', 'break main'; + } + + # Shared breakpoints + my @shared_breakpoints = ( + 'fail_start_trace', 'fail_stop_trace', + 'fail_marker_positive', 'fail_marker_detected', + 'fail_marker_negative', + ); + + # Breakpoints for native C + my @c_breakpoints = (); + + # Breakpoints for Wasm + my @wasm_breakpoints = ( + 'fail_marker_group1', + + # 'os_mmap', + # 'wamr_malloc', + # 'wamr_realloc', + # 'wamr_free', + ); + my @breakpoints = ( + @shared_breakpoints, $is_wasm ? @wasm_breakpoints : @c_breakpoints, + ); + push @gdb_args, '-ex', "break $_" for @breakpoints; + + # Autostart execution + push @gdb_args, '-ex', ( $is_baremetal ? 'continue' : 'run' ); + + system( 'gdb', @gdb_args ); + + if ($is_baremetal) { + say "Killing qemu with pid $qemu_pid..."; + kill 'TERM', $qemu_pid; + waitpid( $qemu_pid, 0 ); + } }, '30. Plot Results' => sub {