Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"No frame is currently executing in specified block" error on gdb

Tags:

c++

gdb

I'm implementing a print_array function in C++ and was using gdb to debug it. There seems to be an issue in the for loop but I really cannot understand why.

The code is:

void print_array(const int array[], const int length) {
    cout << "[";
    for (int i=0; i<length; i++) {
        // Last element
        if (i == length-1) {
            cout << array[i] << "]" << endl;
        } else {
            // Any other element
            cout << array[i] << ", ";
        }
    }
    cout << endl;
}

The main function is:

int main() {

    int array[] = {1, 3, 5, 7, 9, 15, 15, 16, 40, 70};
    int length = 10;

    cout << "Array is = ";
    print_array(array, length);
.
.
.

Debugging this with gdb, and setting it to watch i, I get the following

.
.
.
Thread 2 hit Hardware watchpoint 4: i

Old value = 9
New value = 10
0x0000000100001afd in print_array (array=0x7fff5fbff8e0, length=10) at binary_search.cpp:8
8       for (int i=0; i<length; i++) {
(gdb) 
No frame is currently executing in specified block
0x0000000100001b02 in print_array (array=0x7fff5fbff8e0, length=10) at binary_search.cpp:8
8       for (int i=0; i<length; i++) {
(gdb) 
No frame is currently executing in specified block
Command aborted.
(gdb) 

The basic thing to check would be the for loop going over the array, which does not seem to be the case (unless I'm missing something obvious).

The "real reason" to be asking this question is that gdb seems to be giving weird results in general. I've installed in Mac 10.12.3 for which there is no support as is. As such, the installation was lengthy and I have seen other similar cases online where people ran into weird issues after installing gdb on Mac 10.12.3.

like image 362
mcansado Avatar asked Feb 21 '17 15:02

mcansado


1 Answers

“No frame is currently executing in specified block" means that gdb tried to read from a memory address which doesn't belong to a frame of the application.

At this point of the debugging:

Thread 2 hit Hardware watchpoint 4: i

Old value = 9
New value = 10
0x0000000100001afd in print_array (array=0x7fff5fbff8e0, length=10) at binary_search.cpp:8
8       for (int i=0; i<length; i++) {

the loop-condition is no longer true and the application wants to continue after the for-loop. But GDB is still watching the memory-address where i was.

Delete the hardware watchpoint with delete 4 and it should be possible to continue the debugging.

like image 106
Felix Lechenbauer Avatar answered Sep 22 '22 21:09

Felix Lechenbauer