#2824·pwndbg

Telescope can't parse expressions with symbols that contain spaces without extra escaping

Author: Ninja3047Created Apr 1, 2025Updated Sep 28, 2026
Labelsbug

Description

C++ function symbols contain spaces a lot of the time so in order to reference them in an expression, you can do something like

pwndbg> p/x &'Circle::calculateArea() const'
$2 = 0x1660

This unfortunately does not work the same way for the telescope command (and likely most other pwndbg commands that take in gdb expressions)

pwndbg> telescope &'Circle::calculateArea() const'
usage: telescope [-h] [-r] [-f] [-i] [address] [count]
telescope: error: argument address: debugger couldn't resolve argument '&Circle::calculateArea() const': A syntax error in expression, near the end of `&Circle::calculateArea() const'.

a workaround is to double quote the expression

pwndbg> telescope "&'Circle::calculateArea() const'"
00:0000│  0x555555555660 (Circle::calculateArea() const) ◂— movsd xmm1, qword ptr [rdi + 0x28]
01:0008│  0x555555555668 (Circle::calculateArea() const+8) ◂— add eax, 0x9b3
02:0010│  0x555555555670 (Circle::calculateArea() const+16) ◂— sal edx, 0xf
03:0018│  0x555555555678 ◂— nop dword ptr [rax + rax]
04:0020│  0x555555555680 (Circle::display() const) ◂— push r15
05:0028│  0x555555555688 (Circle::display() const+8) ◂— mov r14, qword ptr [rip + 0x2951]
06:0030│  0x555555555690 (Circle::display() const+16) ◂— lea esi, [rip + 0xa08]
07:0038│  0x555555555698 (Circle::display() const+24) ◂— add byte ptr [rax], al

This actually might be non-trivial to fix if we want to match gdb behavior. Since telescope can take additional arguments after the expression, the code uses gdb.string_to_argv to lex the arguments. Unfortunately, this removes the inner single quotes required for the expression to parse.

python
(Pdb) p command_line
"&'Circle::calculateArea() const' 0x100"
(Pdb) p gdb.string_to_argv(command_line)
['&Circle::calculateArea() const', '0x100']
python
pwndbg> p/x '&Circle::calculateArea() const'
No symbol "&Circle::calculateArea() const" in current context.
pwndbg> p/x &'Circle::calculateArea() const'
$2 = 0x1660

Steps to reproduce

Compile the following C++ sample code with debug symbols.

cpp
#include <iostream>
#include <string>

// Base class
class Shape {
protected:
    std::string name;
    
public:
    // Constructor
    Shape(const std::string& shapeName) : name(shapeName) {}
    
    // Virtual method to be overridden
    virtual double calculateArea() const {
        return 0.0;
    }
    
    // Virtual method to display information
    virtual void display() const {
        std::cout << "Shape: " << name << std::endl;
    }
    
    // Virtual destructor
    virtual ~Shape() {
        std::cout << "Shape destructor called for " << name << std::endl;
    }
};

// Derived class: Circle
class Circle : public Shape {
private:
    double radius;
    
public:
    // Constructor
    Circle(const std::string& circleName, double r) 
        : Shape(circleName), radius(r) {}
    
    // Override calculateArea
    double calculateArea() const override {
        return 3.14159 * radius * radius;
    }
    
    // Override display
    void display() const override {
        std::cout << "Circle: " << name << std::endl;
        std::cout << "Radius: " << radius << std::endl;
        std::cout << "Area: " << calculateArea() << std::endl;
    }
    
    // Destructor
    ~Circle() override {
        std::cout << "Circle destructor called for " << name << std::endl;
    }
};

// Another derived class: Rectangle
class Rectangle : public Shape {
private:
    double width;
    double height;
    
public:
    // Constructor
    Rectangle(const std::string& rectName, double w, double h)
        : Shape(rectName), width(w), height(h) {}
    
    // Override calculateArea
    double calculateArea() const override {
        return width * height;
    }
    
    // Override display
    void display() const override {
        std::cout << "Rectangle: " << name << std::endl;
        std::cout << "Width: " << width << ", Height: " << height << std::endl;
        std::cout << "Area: " << calculateArea() << std::endl;
    }
    
    // Destructor
    ~Rectangle() override {
        std::cout << "Rectangle destructor called for " << name << std::endl;
    }
};

int main() {
    // Create objects dynamically
    Shape* shapes[3];
    shapes[0] = new Shape("Generic Shape");
    shapes[1] = new Circle("My Circle", 5.0);
    shapes[2] = new Rectangle("My Rectangle", 4.0, 6.0);
    
    // Using polymorphism to call overridden methods
    std::cout << "Displaying all shapes:" << std::endl;
    for (int i = 0; i < 3; i++) {
        shapes[i]->display();
        std::cout << "--------------------" << std::endl;
    }
    
    // Clean up memory
    for (int i = 0; i < 3; i++) {
        delete shapes[i];
    }
    
    return 0;
}

My setup

pwndbg> version
Pwndbg:   2025.02.19
Python:   3.12.9 (main, Feb  4 2025, 14:38:38) [GCC 14.2.1 20241116]
GDB:      16.2
Capstone: 5.0.5
Unicorn:  2.1.3
Pwnlib:   4.14.0
pwndbg>