cida

How to find an unused variable in IDA?


I have a very simple program that declares a few variables and prints Hello! I tried to find where the unused variables are stored in the IDA like I found the Hello! (by clicking the lea rcx, _Format ; "Hello!") but I couldn't find their name or anything. The code is

#include <stdio.h>

// global variables
char my_char = 'b';
short my_short = 4000;
int my_int = 10;
long my_long = 65535;
double my_double = 4.32;

int main() {
    printf("Hello!");
    return 0;
}

I think theyr'e supposed to be in the .data but can't find it .data


Solution

  • I found that if the variable is not used it will not show in the data. For it to show I added code that utilities the variables in the main() and now it does show in the .data SEG in the IDA.

    #include <stdio.h>
    
    // global variables
    char my_char = 'b';
    short my_short = 4000;
    int my_int = 10;
    long my_long = 65535;
    double my_double = 4.32;
    
    int main() {
        printf("Hello!\n");
    
        printf("%c\n", my_char);
        printf("%d\n", my_short);
        printf("%d\n", my_int);
        printf("%ld\n", my_long);
        printf("%f\n", my_double);
    
        return 0;
    }