[lldb-dev] Is there a way to know whether a variable have been init?

Kun LIng lingcc at lingcc.com
Sat Aug 30 20:19:51 PDT 2014


ping


 






lingcc



52mianshiti.com/Lingcc.com





北京市昌平区




 
 
 
------------------ Original ------------------
From: "Kun  LIng"; 
Date: 2014年8月30日(星期六) 下午3:58
To: "lldb-dev"; 
Subject: [lldb-dev] Is there a way to know whether a variable have been init?

 
Hi all,
    I am currently using python interface to run a non-interactively script based on LLDB to trace the variable changing during each step during the program running. 

    C allows a variable to be declared at first without initialization.  And the value of the variable after declaration could be a random value before initialized according to my test using LLDB with the following code compiled by clang+llvm. 

----Example Code ----
#include <stdio.h>
#include <stdlib.h>
int g = 42;
float u = 5;
struct node {
  int field;
  struct node* next;
};
void f() {
    g = g + 1;
    printf("Hello world!\n");
}


int main(int argc, char *argv[])
{
  int x;
  int y=10;
  x  = y+1;
  struct node* root = (struct node*)malloc(sizeof(struct node));
  root->field = 3;
  root->next = (struct node*)malloc(sizeof(struct node));
  root->next->field = 2;
  free(root->next);
  free(root);


  int i = 0;
  i = i + 1;
  f();
  return 0;
}


-----End Example Code ----

   My question is:
   In LLDB, is there a way to check whether a variable is currently be declared, and have not been initialized? So that my non-interactively script could check this, and ignore to show it before initialized ?
   Thanks very much.

Best,
Kun Ling
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20140831/11d6a6d1/attachment.html>


More information about the lldb-dev mailing list