kgdb按照资料说可以使用网络(kgdboe)和串口连接(kgdboc)等方式连接。

这里使用后者,资料比较多,下面是自己在Mac上进行配置连接的过程。

先说一下环境:

主机:Mac OSX 10.10.3

虚拟:Parallels Desktop 10.1.2 里面装 Ubuntu Server 14.14.02 (kernel 3.16)

下载kernel源码版本:3.16.7

下载gdb源码版本:7.9

虚拟机上的准备工作

1. 下载kernel源码(kernel.org)

2. apt-get install libncurses5-dev,不装这个下面的menuconfig会提示没有相关头文件

3. make menuconfig进行配置,打开KGDB相关的设置,网上比较多

4. make, make modules_install, make install

(make之前修改源码根目录下的Makefile文件,将编译优化选项O2改为Og,直接O0的话编译会报错)

5. 重启之后原来的PD共享文件夹可能看不到了,这时候可以重新装一遍Parallel Tools(Actions->Reinstall Parallels Tools)

6. 将编译目录tar一下,通过共享文件夹拷到mac主机上便于以后gdb使用(或许只把vmlinux拷到别的源码目录就可以?)

Mac上的准备工作

1. 在Parallels Desktop中为Linux虚拟机添加一个串口

注意:source中选择new socket,然后填一个有权限的路径,一般可以放在/tmp目录下,名称任意。Mode选择Server

2. 安装socat

虚拟机机内部是一个串口设备在外部系统中表示为一个unix domain socket(可以进行输入输出),而使用终端模式调试的话,还是要用相应的终端软件去连接到一个终端。socat就是把这个unix domain socket转接到一个虚拟终端。如果是物理机子的话就是直接可以用终端软件通过串口线连接了。

brew install socat

当然这要求电脑上已经装了brew

3. 编译安装gdb

这个不能用brew直接装,也不能用xcode带的lldb,一定要手工编译源码。解压后进入源码目录执行

./configure --target=x86_64-linux-gnu

target表示要调试的目标代码是x86 64 Linux平台上的,如果不指定的话会生成mac平台上的这样是没有办法载入vmlinux映像进行调试的。其实还有个host参数就是gdb运行的平台,这里默认会选择mac平台,因此不用修改。

make
make install

这样得到的可执行文件是x86_64-linux-gnu-gdb,相应的命令行不能直接输入gdb,而要打x86_64-linux-gnu-gdb,程序输出如下:

hgf-mbpr:gdb-7.9 hegaofeng$ x86_64-linux-gnu-gdb
GNU gdb (GDB) 7.9
Copyright (C) Free Software Foundation, Inc.
License GPLv3+: GNU GPL version or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-apple-darwin14.3.0 --target=x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb)

注意查看‘This GDB was configured as --host...’这一行,应该和上述的配置一样。

调试连接

1. 设置kgdboc的参数

# echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc

即kgdboc通过虚拟机的ttyS0来连接,就是我们在PD中添加的那个虚拟串口

2. 中断内核

echo g > /proc/sysrq-trigger

3. 在mac中用socat建一个串口设备ttyS0

$ socat UNIX-CONNECT:/tmp/linuxserver_ttys0 pty,link=/tmp/ttyS0

这样就可以通过这个设备和虚拟机内部的串口通信了(PD里添加的串口设备使用socket模式,文件名为/tmp/linuxserver_ttys0)

4. 在mac中打开x86_64-linux-gnu-gdb 参数是编译生成的vmlinux映像

hgf-mbpr:linux-3.16. hegaofeng$ x86_64-linux-gnu-gdb vmlinux
GNU gdb (GDB) 7.9
Copyright (C) Free Software Foundation, Inc.
License GPLv3+: GNU GPL version or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-apple-darwin14.3.0 --target=x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from vmlinux...done.

最后表示vmlinux载入成功。

5. 连接虚拟机机内核,输入target remote /tmp/ttyS0, /tmp/ttyS0就是我们用socat建立的

(gdb) target remote /tmp/ttyS0
Remote debugging using /tmp/ttyS0
kgdb_breakpoint () at kernel/debug/debug_core.c:
wmb(); /* Sync point after breakpoint */
(gdb)

此时gdb已经连接到了内核,可以输入命令进行调试了。

Mac下 KGDB连接Linux的更多相关文章

  1. Mac下如何连接linux服务器(SSH)-比较好用的SSH工具推荐

    Mac下如何连接linux服务器(SSH) 1.用mac自带终端连接 步骤如下: 打开终端,在顶部shell菜单中选择新建远程连接 在右侧服务器窗口点击+号,添加服务器,输入IP等信息 输入用户名,点 ...

  2. mac 下配置连接Linux服务器方法,上传下载文件操作

    1.先按照文档在本地生成SSHkey 2.mac输入 sudo -i 进入超级管理员#模式下,然后 创建用户 #useradd XXXadmin #passwd XXXadmin XXXadmin用户 ...

  3. Mac下重新编译Linux内核

    Mac下重新编译Linux内核 操作系统实验,要求添加系统调用并重新编译内核,这里记录一下编译内核的过程 0.下载VirtualBox 博主一直用parallel desk,但因为驱动等问题,在PD上 ...

  4. 购买阿里云ECS+安装宝塔面板+Mac下怎么连接阿里云ECS服务器

    1.购买阿里云ECS 2.重置实例密码 这个有点对用户不友好,实际意思就是设置服务器的root登录密码 3.配置安全组放行端口 因为服务器需要从宝塔网站download安装包,包括一些常用的服务比如S ...

  5. windows下plsql连接linux下的oracle数据库

    windows下plsql连接linux下的oracle数据库 经过多方查找,终于找到解决办法,特此记录下来,共享之. PL/SQL Develorper:目前未发现可以在Linux系统中安装的版本. ...

  6. Mac下ssh连接远程服务器时自动断开问题

    在mac下使用securecrt通过ssh连接远程服务器时,总会一段时间没有动作后,ssh被自动断开.在windows下用xmanager貌似没有遇到过这个问题. 在网上找了解决方法如下: 客户端配置 ...

  7. Mac下Qt连接MySQL 驱动问题

    Mac OS X下Qt的mySQL driver编译安装 原创文章,采用CC协议发布,转载请注明: 转载自canX.me 本文链接地址: Mac OS X下Qt的mySQL driver编译安装 – ...

  8. 记录Window系统下myeclipes连接linux下mysql所出现的一个bug

    记录myeclipes远程连接mysql所出现的一个bug 今天在玩框架hibernate时,出现一个非常费解的bug,话不多说,先看bug Access denied for user 'root' ...

  9. mac下进行连接pptp协议

    环境:mac系统 软件:shimo 协议:pptp协议 说明: mac 自带vpn已经不支持 pptp协议的vpn,可以下载shimo连接. mac下进行vpn连接pptp协议操作方法: 下载: 链接 ...

随机推荐

  1. Map-560. Subarray Sum Equals K

    Given an array of integers and an integer k, you need to find the total number of continuous subarra ...

  2. 一种基于zookeeper的分布式队列的设计与实现

    package com.ysl.zkclient.queue; import com.ysl.zkclient.ZKClient; import com.ysl.zkclient.exception. ...

  3. jvm高级特性(4)(内存分配回收策略)

    JVM高级特性与实践(四):内存分配 与 回收策略 一. 内存分配 和 回收策略 1,对象内存分配的概念: 往大方向讲,它就是在堆上分配(但也可能经过JIT编译后被拆散为标量类型并间接地栈上分配), ...

  4. SVN图形客户端上传静态库.a文件失败

    1.原因客户端未添加静态库 2.解决办法 到项目静态库所在目录用命令行添加静态库文件 svn add ****.a 3.可能存在问题 Mac OS的自带SVN版本过低不能添加,报错如下: svn: E ...

  5. manifest.xml

    main action 和 laucher的categoty If either the MAIN action or LAUNCHER category are not declared for o ...

  6. (转)Mysql备份还原数据库之mysqldump实例及参数详细说明

    http://www.xuejiehome.com/blfl-2.html http://www.cnblogs.com/xuejie/archive/2013/01/11/2856911.html ...

  7. Java之集合(二)ArrayDeque

    转载请注明源出处:http://www.cnblogs.com/lighten/p/7283928.html 1.前言 上章讲解了Java中的集合接口和相关实现抽象类,本章开始介绍一些具体的实现类,第 ...

  8. python中range、xrange和randrange的区别

    range 函数说明:range([start,] stop[, step]),根据start与stop指定的范围以及step设定的步长,生成一个列表. xrange 函数说明:和range 的用法完 ...

  9. springboot设置静态资源不拦截的方法

    springboot设置静态资源不拦截的方法 springboot不拦截静态资源需配置如下的类: import org.springframework.context.annotation.Confi ...

  10. sql 保留两位小数

    select convert(decimal(18,2),1800.2669)