Cross Debugging with GDB: Embedded Linux

This is suitable for environments with limited resources and insufficient memory, to avoid out-of-memory errors caused by running gdb.

The uclibc platform does not yet support this functionality.

文章目录

    • Install gdb-multiarch on PC
    • Run gdbserver on DUT
    • Prepare sysroot
    • Run gdb-multiiarch on PC
    • GDB Debug by Reading Coredump
      • About coredump
      • Prepare FW with coredump enabled
      • Enable coredump size & name
      • Permernently enable coredump size when build SDK
    • Check Symbol From File
      • Check library or program dependencies
      • Make sure that the debugging program have symbols

Install gdb-multiarch on PC

install MINGW64 MSYS2 environment
in MSYS2 environment install MINGW gdb-multiarch

$ pacman -S mingw-w64-x86_64-gdb-multiarch

press ‘Y’ to install all depended libraries

Run gdbserver on DUT

  1. prepare gdbserver on buildroot for target platform
  2. change gdbserver $ chmod 755 gdbserver
  3. gdbserver cmd
    ./gdbserver localhost:2001 <bin + args>
  4. check LD_LIBRARY_PATH
$ echo $LD_LIBRARY_PATH
/system/lib

Prepare sysroot

Downlaod target_debug to C:\msys64\home\imxx\ 下, this is MYSYS2 home

Run gdb-multiiarch on PC

  1. open MINGW
(gdb) gdb-multiarch ./testOnDemandRTSPServer # 這個檔案必須是DUT 上執行的相同一個
//(gdb) gdb-multiarch ./target_debug/system/bin/testOnDemandRTSPServer   # 或是直接執行 sysroot 裡面的對應執行檔
(gdb) set architecture arm
(gdb) set sysroot ./target_debug # 這就是方才複製 SDK/fs/rootfs/output/target_debug 位置
(gdb) set solib-search-path ./target_debug/system/lib # 此位置必須取代 DUT $LD_LIBRARY_PATH
(gdb) target remote 172.16.35.42:2001 # 也就是 DUT IP + gdb server port
(gdb) b main # 設置中斷點在 main function
(gdb) continue
  1. Check shared library info
(gdb)  info shared

output

(gdb) info shared
From        To          Syms Read   Shared Object Library
0xb6f84800  0xb6f97408  Yes         ./target_debug/lib/ld-linux-armhf.so.3
0xb6f3c930  0xb6f6c860  Yes         ./target_debug/system/lib/libinf.so.1
0xb6f235e8  0xb6f23cd4  Yes         ./target_debug/system/lib/libaftr.so.3
0xb6f082e8  0xb6f0fc28  Yes         ./target_debug/system/lib/libvftr.so.3
0xb6d86704  0xb6e7c618  Yes         ./target_debug/system/lib/libmpp.so.3
0xb6daee78  0xb6db1d8c  Yes         ./target_debug/usr/lib/libjson-c.so.2
0xb6d98810  0xb6d9ae68  Yes         ./target_debug/lib/librt.so.1
0xb6d1c9b8  0xb6d6f76c  Yes         ./target_debug/usr/lib/libasound.so.2
0xb6c07d58  0xb6cd81fc  Yes         ./target_debug/usr/lib/libtensorflow-lite-optim.so
0xb6bb4974  0xb6bbbd4c  Yes         ./target_debug/usr/lib/libz.so.1
0xb6b6b0d0  0xb6b99c70  Yes         ./target_debug/usr/lib/libcurl.so.4
0xb6b1a414  0xb6b44020  Yes         ./target_debug/usr/lib/libssl.so.1.1
0xb69bd000  0xb6a9c950  Yes         ./target_debug/usr/lib/libcrypto.so.1.1
0xb6906048  0xb694d398  Yes         ./target_debug/lib/libstdc++.so.6No          /lib/libm.so.6
0xb682fdf8  0xb683abe4  Yes         ./target_debug/lib/libgcc_s.so.1No          /lib/libpthread.so.0No          /lib/libc.so.6
0xb66fb97c  0xb66fc234  Yes         ./target_debug/lib/libdl.so.2No          /lib/libatomic.so.1No          /lib/libnss_files.so.2

GDB Debug by Reading Coredump

About coredump

A core dump, also known as a “core dump,” is a snapshot of memory taken at the moment a process crashes abruptly during its execution.

When a program encounters an unhandled exception internally within a process, the operating system saves a dump of the process’s current memory, register states, running stack, and other information into a file. This file is a binary file that can be analyzed using tools like gdb, elfdump, and objdump to examine specific contents.

Reading a core dump typically consumes less memory compared to running the binary with libraries containing symbols, as it doesn’t require loading those libraries during the analysis process.

Prepare FW with coredump enabled

Core dumps are not enabled by default in the most SDK. You need to recompile the Linux kernel configuration to generate the firmware.

$ cd SDK/linux; make menuconfig
General setup -> configure standard kernel features -> Enable ELF core dumps

Enable coredump size & name

  1. file size
$ ulimit -a 
core file size (blocks)         (-c) 0 << 
data seg size (kb)              (-d) unlimited
scheduling priority             (-e) 0
file size (blocks)              (-f) unlimited
pending signals                 (-i) 3321
max locked memory (kb)          (-l) 64
max memory size (kb)            (-m) unlimited
open files                      (-n) 1024
POSIX message queues (bytes)    (-q) 819200
real-time priority              (-r) 0
stack size (kb)                 (-s) 8192
cpu time (seconds)              (-t) unlimited
max user processes              (-u) 3321
virtual memory (kb)             (-v) unlimited
file locks                      (-x) unlimited
$  ulimit -c unlmited << set coredump unlimited size
  1. coredump path
$ cat  /proc/sys/kernel/core_pattern
core
$ echo "/tmp/core.%p" > /proc/sys/kernel/core_pattern --> set to pid name

coredump naming rules
3. GDB read coredump

  • you need to prepare target binary with debug symbol & sysroot
  • active GDB
$ ./gdb <binary with debug symbol> <coredump name>
$ (gdb) set sysroot ./target_debug/
$ info shared  << 查看有關library
$ info stack << 查看發生segfault 的函數傳遞

Permernently enable coredump size when build SDK

ulimit needs to be used after the user logs in and applies only to that logged-in environment.

To change the default ulimit of Linux kernel so that it takes effect during the rcS stage, modifications are required in linux/include/asm-generic/resource.h. However, defining this could lead to customers altering our Linux default values, which is why SDK does not use it by default.

[RLIMIT_CORE]        = {   64*1024*1024,  RLIM_INFINITY }

Check Symbol From File

Check library or program dependencies

Before debugging, you may need to know the dependency of target program

$ arm-augentix-linux-gnueabi-ldd --root . <file>libpthread.so.0 => /lib/libpthread.so.0 (0x8badf00d)libc.so.6 => /lib/libc.so.6 (0x8badf00d)ld-linux.so.3 => /lib/ld-linux.so.3 (0x8badf00d)
(ignore)

Make sure that the debugging program have symbols

You might check whether debug symbols exist with utils file in DUT.

$ file ld-2.22.so
ld-2.22.so: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, not stripped

On the other hand, check whether the section debug_info is in the ELF works also

$ arm-augentix-linux-gnueabi-objdump --syms ld-2.22.so | grep .debug_info
00000000 l    d  .debug_info    00000000              .debug_info

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/867139.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

三级_01_网络系统结构与设计的基本原则

1.下列关于RPR技术的描述中&#xff0c;错误的是()。 RPR与FDDI一样使用双环结构 在RPR环中&#xff0c;源节点向目的节点成功发出的数据帧要由目的节点从环中收回 RPR环中每一个节点都执行MPLS公平算法 RPR环能够在50ms内实现自愈 2.下列关于RPR技术的描述中&#xff0c;…

Vue项目使用mockjs模拟后端接口

文章目录 操作步骤1. 安装 mockjs 和 vite-plugin-mock2. 安装 axios3. 创建mock路径4. 配置 viteMockConfig5. 编写第一个mock接口6. 创建 createProdMockServer7. 配置 axios8. 编写请求接口9. 在页面中使用 操作步骤 1. 安装 mockjs 和 vite-plugin-mock vite-plugin-mock …

springboot的健身房预约管理系统-计算机毕业设计源码75535

目录 1 绪论 1.1 选题背景与意义 1.2国内外研究现状 1.3论文结构与章节安排 1.4开发技术 1.4.1 Java技术 1.4.2MVVM模式 1.4.3B/S结构 1.4.4SpringBoot框架 1.4.5 Mysql数据库 2系统分析 2.1 可行性分析 2.1.1经济可行性 2.1.2技术可行性 2.1.3操作可行性 2.2 系…

SpringBoot 自定义异常返回数据格式

Spring Boot 默认异常处理 当我们用 spring boot 开发接口是&#xff0c;当遇到异常时返回的数据格式是如下形式的 {"timestamp": "2024-07-06T02:48:55.79100:00","status": 404,"error": "Not Found","path":…

在 Windows 上安装移动应用和Amazon Appstore

https://support.microsoft.com/zh-cn/windows/在-windows-上安装移动应用和amazon-appstore-f8d0abb5-44ad-47d8-b9fb-ad6b1459ff6c

【Linux】GNU是什么

GNU是一个自由软件项目&#xff0c;其全称是“GNUs Not Unix!”&#xff0c;由理查德斯托曼&#xff08;Richard Stallman&#xff09;于1983年发起。GNU项目的目标是创建一个完全自由的操作系统&#xff0c;包括一整套完全自由的软件工具&#xff0c;以取代Unix系统。这里的“…

matlab 花瓣线绘制

matlab 花瓣线绘制 clc,clear,close all; % 创建一个范围内的 x 和 y 值 x linspace(-1.5, 1.5, 100); y linspace(-1.5, 1.5, 100);% 创建一个网格来表示 x 和 y 值的组合 [X, Y] meshgrid(x, y);% 计算方程的左边和右边的值 LHS1 X.^2 Y.^2; RHS1 X.^4 Y.^4;LHS2 X.…

接口对接json

public AjaxResult zhihuiya(RequestBody ZlRecord zlRecord) {//查看用户或者部门有没有下载次数SysUser user SecurityUtils.getLoginUser().getUser();ZlCount zlCount newLabelMapper.selectUserCount(user.getUserId());if (ObjectUtils.isEmpty(zlCount)){ZlCount zlCo…

vue2-vue3响应式原理

我们先来看一下响应式意味着什么&#xff1f;我们来看一段代码&#xff1a; m有一个初始化的值&#xff0c;有一段代码使用了这个值&#xff1b;那么在m有一个新的值时&#xff0c;这段代码可以自动重新执行&#xff1b; let m 20 console.log(m) console.log(m * 2)m 40上…

计算机网络-IP组播基础

一、概述 在前面的学习交换机和路由协议&#xff0c;二层通信是数据链路层间通信&#xff0c;在同一个广播域间通过源MAC地址和目的MAC地址进行通信&#xff0c;当两台主机第一次通信由于不清楚目的MAC地址需要进行广播泛洪&#xff0c;目的主机回复自身MAC地址&#xff0c;然后…

【语音识别算法】深度学习语音识别算法与传统语音识别算法的区别、对比及联系

深度学习语音识别算法与传统语音识别算法在理论基础、实现方式、性能表现等方面存在显著区别&#xff0c;同时也有一些联系。下面将从几个方面详细比较这两种方法&#xff0c;并给出应用实例和代码示例。 一、理论基础与实现方式 1.传统语音识别算法&#xff1a; 特征提取&a…

【Android】ADB 使用指南

ADB 使用指南 Android Debug Bridge (ADB) 是一个功能强大的命令行工具&#xff0c;可以让你直接与连接的 Android 设备进行通信。它可以用于多种用途&#xff0c;包括安装和调试应用程序、传输文件、执行命令等。本指南将介绍 ADB 的基本使用方法和常用命令。 安装 ADB 在 …

MySQL数据库树状结构查询

一、树状结构 MySQL数据库本身并不直接支持树状结构的存储&#xff0c;但它提供了足够的灵活性&#xff0c;允许我们通过不同的方法来模拟和实现树状数据结构。具体方法看下文。 数据库表结构&#xff1a; 实现效果 查询的结果像树一样 二、使用 以Catalog数据表&#xff0c…

昇思25天学习打卡营第18天 | 基于MobileNetv2的垃圾分类

内容介绍&#xff1a; MobileNet网络是由Google团队于2017年提出的专注于移动端、嵌入式或IoT设备的轻量级CNN网络&#xff0c;相比于传统的卷积神经网络&#xff0c;MobileNet网络使用深度可分离卷积&#xff08;Depthwise Separable Convolution&#xff09;的思想在准确率小…

安装node软件 文件夹里没有node_modules 包 是怎么回事

在安装Node.js时&#xff0c;它会自动创建一个名为node_modules的文件夹&#xff0c;并将相关的包安装到该文件夹中。如果你在安装后发现该文件夹不存在&#xff0c;那么可能是以下几种情况之一&#xff1a; 安装过程中出现错误&#xff0c;导致node_modules文件夹未能正确创建…

CSS选择器:nth-child()

CSS3 :nth-child() 选择器 :nth-child(n) 选择器匹配属于其父元素的第 N 个子元素&#xff0c;不论元素的类型。 n 可以是数字、关键词或公式。 Odd 和 even 是可用于匹配下标是奇数或偶数的子元素的关键词&#xff08;第一个子元素的下标是 1&#xff09;。 使用公式 (an b)。…

python爬虫爬取中国国际招标有限公司

python爬虫爬取中国国际招标有限公司 python爬取数据存储到redis中 # -*- coding: utf-8 -*- # 中国国际招标有限公司 import re from datetime import datetimeimport redis import requests from lxml import etree from config import REDIS_IP, REDIS_PORT, REDIS_DB, R…

077、Python 关于魔术方法

概念&#xff1a; 魔术方法&#xff08;Magic Methods&#xff09;&#xff0c;也叫魔法方法。是指有特殊用途和意义的方法。 定义&#xff1a; 方法在定义时&#xff0c;方法名使用双下划线开头和结尾。 一些常见的魔术方法&#xff1a; 初始化方法&#xff1a; __init__…

ChatGLM2-6B 运行代码解读(一)

目录 一、整体结构 二、终端运行 2.1 下载模型文件 2.2 修改代码 2.3 运行 本文主要对 ChatGLM2-6B 的运行代码进行解读。 一、整体结构 项目的整体结构如下所示。 node@node:~/ChatGLM2-6B$ tree -L 1 . ├── api.py ├── cli_demo.py #命令行运行 ├── e…

Nginx-http_limit_req_module模块

文章目录 前言一、ngx_http_limit_req_module模块二、指令1.limit_req_zone2.limit_req3.limit_req_log_level4.limit_req_status 实验burst取默认0的情况burst不取默认值 总结 前言 如何限制每个客户端每秒处理请求数 一、ngx_http_limit_req_module模块 生效阶段&#xff1…