像使用gdb一样,使用perl debugger进行调试

调试perl脚本,通过-d选项来启动perl debugger,例如:

$ perl -d ./test.pl

这里我们先花点时间,把perl的调试环境配置的好使些。

1、增加对Readline的支持

缺省的perl调试器不支持Readline功能,所以,如果你想按up键往前翻历史命令的话,会出现如下乱码:

^[[A^[[A^[[A^[[A

需要安装模块: Term::ReadKey,Term::ReadLine,Term::ReadLine::Perl(其中后两个我没搞清楚是否重复,反正全装上了)
安装模块的方法,参见 http://www.cpan.org/modules/INSTALL.html

2、使用.perldb文件

这个类似于gdb的.gdbinit,可以用来在调试器启动的时候,做些配置工作,预先执行一些命令。需要注意的是,需要将该文件的权限设定为只有创建者可写,即:

-rw-r--r--

否则,perl debugger出于安全的考虑,不会去加载这个文件:

perldb: Must not source insecure rcfile /home/xmj/.perldb.
        You or the superuser must be the owner, and it must not
        be writable by anyone but its owner.

3、打印数组,哈希变量

可以使用Data::Dumper模块,来打印数组,哈希变量的内容,在.perldb中加入如下配置:

$DB::alias{'dump'}  = 's/^dump (.*)/p Dumper($1)/';
sub afterinit {
  push @DB::typeahead, "use Data::Dumper qw(Dumper)";
}

这样,就可以在perldb中,直接使用dump命令来打印:

  DB<10> dump %Options
$VAR1 = 'EnableCheckers';
$VAR2 = [];
$VAR3 = 'DisableCheckers';
$VAR4 = [];

4、保存历史命令

在.perldb中加入如下配置:

&parse_options("HistFile=$ENV{HOME}/.perldb_hist");

下次进入perl debugger的时候,还可以向上翻出早前的历史命令。

———————-
参考链接:
Debugging Perl scripts, http://perlmaven.com/debugging-perl-scripts
Perl Debugger Tutorial: 10 Easy Steps to Debug Perl Program,http://www.thegeekstuff.com/2010/05/perl-debugger/
How can I print the contents of a hash in Perl? http://stackoverflow.com/questions/1162245/how-can-i-print-the-contents-of-a-hash-in-perl
Can the Perl debugger save the ReadLine history to a file? http://stackoverflow.com/questions/6433241/can-the-perl-debugger-save-the-readline-history-to-a-file
How to install CPAN modules,http://www.cpan.org/modules/INSTALL.html
perldebug在线文档:执行命令perldoc perldebug进行查看

Linux下那么多Tracer如何选择

如果你想要在linux下调调kernel, 抓抓程序的性能, 那么首先想到的可能是 OProfile 和 Linux Perf. 但是显然, 开源有一个非常显著地你无法回避的特点, 就是你会有太多的选择: perf, oprofile, systemtap, dtrace4linux, lttng, kgtp, ktap, sysdig, ftrace, eBPF. 是不是已经眼花了? 那么你不能错过这篇文章:

http://www.brendangregg.com/blog/2015-07-08/choosing-a-linux-tracer.html

介绍了目前常用的各类工具:

  1. ftrace
  2. perf_events
  3. eBPF
  4. SystemTap
  5. LTTng
  6. ktap
  7. dtrace4linux
  8. OL DTrace
  9. sysdig

作者非常细心的列出了大量的工具原理及使用教程, 保证会花掉你大把的晚上才能看完.

其实我日常使用的只有 perf, 只能算是 ‘most people’ :)

‘#include_next’ 的用途

最近在阅读开源项目代码的时候看到一个很少见的预处理命令:

#include_next

查询了一下, 并不是标准中的一部分, 属于 GNU 扩展, 使用的场合也比较少, 在某些新旧代码共存时或许会比较常见.

https://gcc.gnu.org/onlinedocs/cpp/Wrapper-Headers.html

2.7 Wrapper Headers

Sometimes it is necessary to adjust the contents of a system-provided header file without editing it directly. GCC’s fixincludes operation does this, for example. One way to do that would be to create a new header file with the same name and insert it in the search path before the original header. That works fine as long as you’re willing to replace the old header entirely. But what if you want to refer to the old header from the new one?

You cannot simply include the old header with ‘#include’. That will start from the beginning, and find your new header again. If your header is not protected from multiple inclusion (see Once-Only Headers), it will recurse infinitely and cause a fatal error.

You could include the old header with an absolute pathname:

#include “/usr/include/old-header.h”

This works, but is not clean; should the system headers ever move, you would have to edit the new headers to match.

There is no way to solve this problem within the C standard, but you can use the GNU extension ‘#include_next’. It means, “Include the next file with this name”. This directive works like ‘#include’ except in searching for the specified file: it starts searching the list of header file directories after the directory in which the current file was found.

OSDT 2015随笔

小雨夹着点雪

大家从各地陆陆续续的赶来

小会场

不过,氛围很好,聊的很热闹

不觉天色已晚

江湖人谈江湖事,以茶代酒风波庄

clang
Clang内部实现

SDCC
SDCC

2015开源开发工具大会

【大会简介】
2015开源开发工具大会是由HelloGCC(www.hellogcc.org)工作组举办的年度开源技术大会。我们希望通过自由,开放,共享的方式来增进大家相互的交流。目前话题主要涉及开源工具链,开源开发工具方面。感谢演讲者为我们贡献精彩的话题 ,感谢各单位和朋友对我们的赞助和支持,欢迎大家免费报名参加。

往年活动:
*) OSDT Workshop 2014: http://www.hellogcc.org/?p=33910
*) HelloGCC Workshop 2013: http://www.hellogcc.org/?p=33518
*) HelloGCC Workshop 2012: http://linux.chinaunix.net/hellogcc2012
*) HelloGCC Workshop 2011: http://linux.chinaunix.net/hellogcc2011
*) HelloGCC Workshop 2010: http://linux.chinaunix.net/hellogcc2010
*) HelloGCC Workshop 2009: https://sites.google.com/site/hellogccworkshop/hui-yi-ri-cheng

【日程安排】

2015年11月21日(周六)中国科学院计算技术研究所 648会议室
14:00 – 14:30 入场、签到
14:30 – 15:30 Clang内部实现,邢明杰 (PDF)
15:30 – 16:30 SDCC,史斌 (PDF)
16:30 – 17:00 自由讨论

题目:Clang内部实现
演讲者:邢明杰
简介:基于clang-3.5.0版本的代码,介绍下clang(http://clang.llvm.org/)的总体架构和各模块的实现,主要包括:驱动器(Driver),前端(Frontend),核心库(Lex,Parser,Sema,AST)。

题目: Introduction to SDCC – A light-weight cross-compile tool-chain targetting 8-bit MCUs
演讲者:史斌
简介: SDCC is a retargettable, optimizing ANSI – C compiler suite that targets the Intel MCS51 based microprocessors (8031, 8032, 8051, 8052, etc.), Maxim (formerly Dallas) DS80C390 variants, Freescale (formerly Motorola) HC08 based (hc08, s08), Zilog Z80 based MCUs (z80, z180, gbz80, Rabbit 2000/3000, Rabbit 3000A, TLCS-90) and STMicroelectronics STM8. Work is in progress on supporting the Microchip PIC16 and PIC18 targets. It can be retargeted for other microprocessors. It includes sdcpp (the preprocessor), sdcc (the compiler), sdas (the assembler), sdld (the linker), ucsim (the simlulator), and a lots of other useful components.

Ben Shi works for a private company as a technical manager. He joined SDCC community in Nov 2013 for filling his spare time, and has made 130+ commits since then, invloving bug fixes in the front end and assembly optimization for the STM8 back end. He will brief introduce SDCC features and his work on it.

【大会地址】
中国科学院计算技术研究所 648会议室,北京海淀区中关村科学院南路6号(大门在中关村南三街)
中国科学院计算技术研究所

【赞助单位】

场地支持 http://www.ict.ac.cn/
合作单位 20131015034226346