gef: Heap analiser not showing after attaching to new process

Your issue will be closed unless you confirm the following:

Step 1: Describe your environment

  • Operating System / Distribution: Linux 5.8.1 / Arch Linux
  • Architecture: x86_64
  • GDB version : 9.2 / Python 3.8.5 / GCC 10.1.0

Step 2: Describe your problem

When analysing the heap of a program, and then attaching to a new program, when trying to analyse the chunks/bins I get an exception

Steps to reproduce

  1. Run gdb on a program (gdb -p PID)
  2. Analyse the heap (heap bins is fine)
  3. Attach to a new program / instance of the same program (att PID)
  4. Analyse the heap of the new program being debugged (heap bins)

Observed Results

  • What happened?
gef➤  heap bins
──────────────────────────────────────── Tcachebins for arena 0x7f24bfb1ec40 ────────────────────────────────────────
───────────────────────────────────────── Fastbins for arena 0x7f24bfb1ec40 ─────────────────────────────────────────
Fastbins[idx=0, size=0x20] [!] Command 'heap bins fast' failed to execute properly, reason: 'NoneType' object has no attribute 'cast'
────────────────────────────────────── Unsorted Bin for arena '*0x7f24bfb1ec40' ──────────────────────────────────────
[!] Command 'heap bins unsorted' failed to execute properly, reason: 'NoneType' object has no attribute 'cast'
─────────────────────────────────────── Small Bins for arena '*0x7f24bfb1ec40' ───────────────────────────────────────
[!] Command 'heap bins small' failed to execute properly, reason: 'NoneType' object has no attribute 'cast'
─────────────────────────────────────── Large Bins for arena '*0x7f24bfb1ec40' ───────────────────────────────────────
[!] Command 'heap bins large' failed to execute properly, reason: 'NoneType' object has no attribute 'cast'

Expected results

  • What did you expect to happen?

Show the heap information (chunks in bins, chunks if ran with heap chunks)

Traces

Since the output is pretty big and it is the same stack trace in all bins, I only provide the stack trace for Unsorted Bin

──────────────────────────── Unsorted Bin for arena '*0x7f24bfb1ec40' ─────────────────────────────

─────────────────────────────── Exception raised ───────────────────────────────
AttributeError: 'NoneType' object has no attribute 'cast'
───────────────────────────── Detailed stacktrace ──────────────────────────────
↳ File "/usr/share/gef/gef.py", line 690, in get_size_t_array()
    →     return dereference(addr).cast(size_t_array)
↳ File "/usr/share/gef/gef.py", line 669, in bins()
    →     return self.get_size_t_array(self.bins_addr, self.num_bins)
↳ File "/usr/share/gef/gef.py", line 693, in __getitem__()
    →     return getattr(self, item)
↳ File "/usr/share/gef/gef.py", line 717, in __getattr__()
    →     return self.__arena[item]
↳ File "/usr/share/gef/gef.py", line 742, in bin()
    →     fd = int(self.bins[idx])
↳ File "/usr/share/gef/gef.py", line 6367, in pprint_bin()
    →     fw, bk = arena.bin(index)
↳ File "/usr/share/gef/gef.py", line 6542, in do_invoke()
    →     nb_chunk = GlibcHeapBinsCommand.pprint_bin(arena_addr, 0, "unsorted_")
↳ File "/usr/share/gef/gef.py", line 2458, in wrapper()
    →     return f(*args, **kwargs)
↳ File "/usr/share/gef/gef.py", line 244, in wrapper()
    →     return f(*args, **kwargs)
↳ File "/usr/share/gef/gef.py", line 3857, in invoke()
    →     bufferize(self.do_invoke)(argv)
───────────────────────────── Last 10 GDB commands ─────────────────────────────
  253  heap bins
  254  att 66976
  255  att 67122
  256  heap bins
  257  heap bins
  258  att 67906
  259  heap bins
  260  heap bin tcache
  261  gef config gef.debug 1
  262  heap bins
───────────────────────────── Runtime environment ──────────────────────────────
* GDB: 9.2
* Python: 3.8.5 - final
* OS: Linux - 5.8.1-arch1-1 (x86_64)

LSB Version:    1.4
Distributor ID: Arch
Description:    Arch Linux
Release:        rolling
Codename:       n/a
────────────────────────────────────────────────────────────────────────────────

NOTE: This error occurs even on the dev branch

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (14 by maintainers)

Most upvoted comments

Good debugging!

You almost got it

def reset_all_caches():
    [...]   
    global __gef_default_main_arena__ 
    __gef_default_main_arena__  = "main_arena"
    return

Forgot to say it was a global variable, but it works like a charm Thanks