# Copyright (C) 2021-2024 Free Software Foundation, Inc. # Copyright (C) 2021-2024 Advanced Micro Devices, Inc. All rights reserved. # This file is part of GDB. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see . # Test the various rocgdb disassemble commands on the kernel code. # disassembly command shows assembly instructions. # # Optimized executables: Please note this test takes into account different # optimization levels for some of its patterns. Optimized binaries may have # different instructions and execution flow, which makes documenting the # individual outputs ineffective. See comments across the test. load_lib rocm.exp require allow_hip_tests standard_testfile .cpp if {[prepare_for_testing "failed to prepare ${testfile}" $testfile $srcfile {debug hip}]} { return -1 } with_rocm_gpu_lock { if ![runto_main] { fail "can't run to main" return -1 } # By default, GDB shows mangled names in disassembly listings. # Force demangling to make it easier to match symbols in the tests below. gdb_test_no_output "set print asm-demangle on" # Set breakpoint in device code. gdb_breakpoint "kernel" "allow-pending" "qualified" gdb_continue_to_breakpoint "kernel" # Check "disassemble /r kernel". # # Sample vega20 output: # # Dump of assembler code for function kernel(): # 0x00007efe8de01600 <+0>: ff 00 a0 be 00 04 00 00 s_mov_b32 s32, 0x400 # 0x00007efe8de01608 <+8>: 80 00 a1 be s_mov_b32 s33, 0 # 0x00007efe8de0160c <+12>: 04 07 66 80 s_add_u32 flat_scratch_lo, s4, s7 # . # . # End of assembler dump. gdb_test_sequence "disassemble /r kernel" "disassemble raw" [list \ "Dump of assembler code for function kernel\\(\\):" \ "\[ \t\]+$hex <\\+0>:\[ \t\]+(\[0-9a-fA-F]+\[ \t\]+)+\[^\r\n\]+" \ "End of assembler dump\." \ ] # The /m and /s options are visually equivalent, so we check both using the # same pattern. # # Sample vega20 output: # # Dump of assembler code for function kernel(): # 24 \{ # 0x00007efe8de01600 <+0>: s_mov_b32 s32, 0x400 # 0x00007efe8de01608 <+8>: s_mov_b32 s33, 0 # 0x00007efe8de0160c <+12>: s_add_u32 flat_scratch_lo, s4, s7 # . # . # End of assembler dump. # # With optimized executables gdb may show any of the source lines depending on # the compiler output. foreach_with_prefix mode {"m" "s"} { gdb_test_sequence "disassemble /$mode kernel" "disassemble machine code" [list \ "Dump of assembler code for function kernel\\(\\):" \ "$decimal\[ \t\]+(\{|\}|tid \+= 1;|volatile int tid = threadIdx\.x)" \ "\[ \t\]+$hex <\\+0>:\[ \t\]+\[^\n\r\]+" \ "End of assembler dump\." \ ] } # Check "x/3i kernel". # # Sample vega20 output: # # 0x7efe8de01600 : s_mov_b32 s32, 0x400 # 0x7efe8de01608 : s_mov_b32 s33, 0 # 0x7efe8de0160c : s_add_u32 flat_scratch_lo, s4, s7 gdb_test_sequence "x/3i kernel" "disassemble 3 instructions" [list \ "\[ \t\]+$hex :(\[ \t\]*)" \ "\[ \t\]+$hex :(\[ \t\]*)" \ "\[ \t\]+$hex :(\[ \t\]*)" ] # Check set disassemble-next-line off followed by n. # Sample vega20 output: # There should not be any disassemble code printed identified by the absence of the character "=>" gdb_test_no_output "set disassemble-next-line off" gdb_test_multiple "n" "next after disassemble-next-line off" { -re "=>.*$gdb_prompt $" { fail $gdb_test_name } -re "$gdb_prompt $" { pass $gdb_test_name } } # Check "set disassemble-next-line on followed by n". # vega20 sample output # There should be disassemble code printed identified by the presense of the character "=>" gdb_test_no_output "set disassemble-next-line on" gdb_test_multiple "n" "next after disassemble-next-line on" { -re "=>.*$gdb_prompt $" { pass $gdb_test_name } -re "$gdb_prompt $" { fail $gdb_test_name } } }