crash.types.bitmap module

The crash.types.bitmap module provides helpers for iterating and scanning in-memory bitmaps.

A bitmap is represented as either an array of unsigned long or as unsigned long *. Each routine below that accepts a gdb.Value requires that it be of either type.

crash.types.bitmap.find_first_set_bit(bitmap: gdb.Value, size_in_bytes: int = None) → int[source]

Return the first set bit in the bitmap

Parameters:
  • bitmap – The bitmap to scan.
  • size_in_bytes – The size of the bitmap if the type is unsigned long *.
Returns:

The position of the first bit that is set, or 0 if all are unset

Return type:

int

Raises:

InvalidArgumentError – The gdb.Value is not of type unsigned long[] or unsigned long *.

crash.types.bitmap.find_first_zero_bit(bitmap: gdb.Value, size_in_bytes: int = None) → int[source]

Return the first unset bit in the bitmap

Parameters:
  • bitmap – The bitmap to scan.
  • start – The bit number to use as a starting position. If the bit at this position is unset, it will be the first bit number yielded.
Returns:

The position of the first bit that is unset

Return type:

int

Raises:

InvalidArgumentError – The gdb.Value is not of type unsigned long[] or unsigned long *.

crash.types.bitmap.find_last_set_bit(bitmap: gdb.Value, size_in_bytes: int = None) → int[source]

Return the last set bit in the bitmap

Parameters:
  • bitmap – The bitmap to scan.
  • size_in_bytes – The size of the bitmap if the type is unsigned long *.
Returns:

The position of the last bit that is set, or 0 if all are unset

Return type:

int

Raises:

InvalidArgumentError – The gdb.Value is not of type unsigned long[] or unsigned long *.

crash.types.bitmap.find_next_set_bit(bitmap: gdb.Value, start: int, size_in_bytes: int = None) → int[source]

Return the next set bit in the bitmap starting at position start, inclusive.

Parameters:
  • bitmap – The bitmap to scan.
  • start – The bit number to use as a starting position. If the bit at this position is unset, it will be the first bit number yielded.
  • size_in_bytes – The size of the bitmap if the type is unsigned long *.
Returns:

The position of the next bit that is set, or 0 if all are unset

Return type:

int

Raises:

InvalidArgumentError – The gdb.Value is not of type unsigned long[] or unsigned long *.

crash.types.bitmap.find_next_zero_bit(bitmap: gdb.Value, start: int, size_in_bytes: int = None) → int[source]

Return the next unset bit in the bitmap starting at position start, inclusive.

Parameters:
  • bitmap – The bitmap to scan.
  • start – The bit number to use as a starting position. If the bit at this position is unset, it will be the first bit number yielded.
  • size_in_bytes – The size of the bitmap if the type is unsigned long *.
Returns:

The position of the first bit that is unset or 0 if all are set

Return type:

int

Raises:

InvalidArgumentError – The gdb.Value is not of type unsigned long[] or unsigned long *.

crash.types.bitmap.for_each_set_bit(bitmap: gdb.Value, size_in_bytes: int = None) → Iterable[int][source]

Yield each set bit in a bitmap

Parameters:
  • bitmap – The bitmap to iterate.
  • size_in_bytes – The size of the bitmap if the type is unsigned long *.
Yields:

int – The position of a bit that is set

Raises:

InvalidArgumentError – The gdb.Value is not of type unsigned long[] or unsigned long *.

crash.types.bitmap.test_bit(bitmap: gdb.Value, bit: int, size_in_bytes: int = None) → bool[source]

Test a bit in a bitmap. Unlike the find family of functions, the index starts at 0.

Parameters:
  • bitmap – The bitmap to use for testing
  • bit – The bit in the bitmap to test, starting at offset 0
  • size_in_bytes (optional, default = None) – The size of the bitmap if a pointer is used.
Returns:

Whether the bit is set or not

Return type:

bool

Raises:

InvalidArgumentError – The gdb.Value is not of type unsigned long[] or unsigned long *.