class access_path¶
An access path describes a memory location as a sequence of steps from some base symbol , with each step represented by a access_path object.
For example, suppose we have the following declarations.
char *p;
char **pp;
char A[10];
float f;
struct mys {
int i;
double d;
};
struct mys s;
struct mys *sp;
We can describe various code artifacts in terms of base and access path as shown in the following table.
| Code artifact | base symbol |
access path |
|---|---|---|
f |
f |
[] |
p[4] |
p |
[ access_path.offset_in_bits(), access_path.star() ] |
&p |
p |
[ access_path.addr() ] |
(*pp)[4] |
pp |
[ access_path.offset_in_bits(), access_path.star(), access_path.star() ] |
*(pp[4]) |
pp |
[ access_path.star(), access_path.offset_in_bits(), access_path.star() ] |
A[5] |
A |
[ access_path.offset_in_bits() ] |
s.d |
s |
[ access_path.offset_in_bits() ] |
ps->d |
ps |
[ access_path.offset_in_bits(), access_path.star() ] |
Where:
- the
dfield is offset 32 bits from the start ofs/*ps, assuming 32-bit integers - 40 is 5*8, and a char is 8 bits
- assuming 32-bit pointers: 4*32 = 128
- 32 is 4*8, and a char is 8 bits
Note that the access operator access_path.addr() can only ever appear in a singleton access path. No other access paths containing the address operator correspond to legal expressions.
- The
xform_exprconstructor takes anaccess_pathargument.
access_path Members¶
| Constructors | none |
| Static Methods | addr(), offset_in_bits(), star() |
| Methods | __repr__(), __str__() |
access_path Details¶
-
class
cs.access_path¶ An access path describes a memory location as a sequence of steps from some base
symbol, with each step represented by aaccess_pathobject.-
static
addr()¶ Get a new access path element corresponding to the address (
&) operator.Return type: access_pathReturns: The newly created access_pathelement.>>> access_path.addr() <cs.access_path &>
-
static
offset_in_bits(off)¶ Get a new access path element corresponding to the offset (
[]) operator, with offset as specified.Parameters: off (int) – The offset, in bits. Return type: access_pathReturns: The newly created access_pathelement.Raises: OverflowError>>> access_path.offset_in_bits(102) <cs.access_path [102]>
-
static
star()¶ Get a new access path element corresponding to the star (
*) operator.Return type: access_pathReturns: The newly created access_pathelement.>>> access_path.star() <cs.access_path *>
-
__repr__()¶ Get a representation of a
access_pathobject that includes information useful for debugging.Return type: str Returns: The string representation. >>> v0 = access_path.addr() >>> repr(v0) '<cs.access_path &>'
-
__str__()¶ Get a simple string representation of a
access_pathobject.Return type: str Returns: The string representation. >>> v0 = access_path.addr() >>> str(v0) '&'
-
static