Project Home
Project Home
Source Code
Source Code
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Python script to debug my binary using gdb on QNX OS: (3 Items)
   
Python script to debug my binary using gdb on QNX OS  
OS: QNX 11.1 Python: 3.10 Host OS: Windows SDP: qnx710
We are using QualCOMM Snapdragon A1B Sample hardware which has QNX OS and supports gdb. We can run through momentics IDE
.

I'm trying to debug my application which will be running on QNX. When I execute the below python program, it doesn't 
execute os.system('file {}'.format(binpath)). It just stopped at gdb prompt.

##Test Program
import os
import subprocess

ip_to_check = ('***.***.*.*')
targetIP_Port = ('***.***.*.*:****')
qnxPath = ('C:/qnx710/host/win64/x86_64/usr/bin')
binpath = ('D:/Project/develop/sample')
#FILE = ('gdbInit.txt')

os.system('cls')

returnStatus = os.system('ping -n 4 {}'.format(ip_to_check))
print('\n')
print('#'*60)

if returnStatus == 1:
    print('Please check the target connection, restart and try again...')
    print('#'*60)
else:   
    cwd=os.getcwd()
    print("Current Working Directory: {0}".format(cwd))
    print('\n')
    print('#'*60)

    print('Changing Directory to qnx path')
    os.chdir(qnxPath)

    cwd=os.getcwd()
    print("Current Working Directory: {0}".format(cwd))
    print('\n')
    print('#'*60)

    os.system('aarch64-unknown-nto-qnx7.1.0-gdb.exe')
    os.system('file {}'.format(binpath))
If I manually execute in command prompt, the symbols are read.

C:/qnx710/host/win64/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-gdb.exe D:/Project/develop/sample

Has anyone tried to automate remote debugging the application using gdb on QNX OS. Can you please point out what is 
wrong in the above script?
Re: Python script to debug my binary using gdb on QNX OS  
Momentics will spawn a pdebug process on the target, via qconn, for you.
For command line GDB you need to manually launch an instance of pdebug on your target.
Re: Python script to debug my binary using gdb on QNX OS  
You can put those commands in the testscript.py
targetIP=xxx.xxx.xxx.xxx
binpath='D:/Project/develop/sample'
gdb.execute(f"target qnx {targetIP}:8000")
gdb.execute(f"file {binpath}")

In gdb console, use `source` command to execute the script.
(gdb) > source  /path/to/testscript.py

To execute the script from outside gdb CLI:
# ntoaarch64-gdb --init-eval-command="source /path/to/testscript.py"

Bonus:
You can run an interactive python shell in the gdb session to test your commands first:
(gdb) > python-interactive
>>> gdb.execute("info inferiors")
>>> # For automation, it might be useful to store the gdb command result to a variable:
>>> pidlist = gdb.execute("info pidlist", to_string=True)

Refence:
 - https://sourceware.org/gdb/onlinedocs/gdb/Basic-Python.html#Basic-Python