GDB reports “no symbol in current context” upon array initialization

狂风中的少年 提交于 2019-12-10 20:15:13

问题


I am attempting to initialize an array with a size of ceil(buflen/125.0) as follows:

long long maxjpg = ceil(buflen/125.0);
long long arr[maxjpg];

I do not receive a compiler error, but GDB reports "no symbol 'arr' in current context". The only fix I have found is by hardcoding a numerical value into the array size like so:

long long arr[5];

I have tried casting, using different variable types, using const and any combination of these approaches. I know that ceil returns a double, I have tried working with that too.

Initializing a value and printing it like so works:

arr[0] = 25;
printf(pos 0 is %d\n", arr[0]);

output: pos 0 is 25

Printing arr[0] through GDB after that modification results in "value has been optimized out".

Minimum viable code to reproduce:

#include <math.h>

int main(void){

long long size = ceil(123.45);    
long long arr[size];

return 0;
}

GDB Fedora 7.4.50.20120120-52.fc17


回答1:


VLAs do not currently work in gdb. There's a bug open about it and an ongoing project to fix it: https://sourceware.org/gdb/wiki/VariableLengthArray

There's an implementation in archer.git that works in some cases, but it isn't considered good enough to go in trunk.



来源:https://stackoverflow.com/questions/19116709/gdb-reports-no-symbol-in-current-context-upon-array-initialization

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!