GDB ʹÓ×—Linux C±à³Ì
¼òÊö
Ò» ÁÐÎļþÇåµ¥
¶þ£ºÖ´ÐгÌÐò
Èý£ºÏÔʾÊý¾Ý
ËÄ£º¶Ïµã(breakpoint)
Î壮¶ÏµãµÄ¹ÜÀí
Áù£®±äÁ¿µÄ¼ì²éºÍ¸³Öµ
Æß. µ¥²½Ö´ÐÐ
°Ë£®º¯ÊýµÄµ÷ÓÃ
¾Å£®»úÆ÷ÓïÑÔ¹¤¾ß
Ê®£®ÐźÅ
GDBµÄʹÓ÷½·¨
¼òÊö
Ò» ÁÐÎļþÇåµ¥
* List
(gdb) list line1,line2
¶þ£ºÖ´ÐгÌÐò
ÒªÏëÔËÐÐ×¼±¸µ÷ÊԵijÌÐò£¬¿ÉʹÓÃrunÃüÁÔÚËüºóÃæ¿ÉÒÔ¸úËæ·¢¸ø¸Ã³ÌÐòµÄÈκβÎÊý£¬°üÀ¨±ê×¼ÊäÈëºÍ±ê×¼Êä³ö˵Ã÷·û(<ºÍ> )ºÍÍâ¿ÇͨÅä·û£¨*¡¢£¿¡¢[¡¢]£©ÔÚÄÚ¡£Èç¹ûÄãʹÓò»´ø²ÎÊýµÄrunÃüÁgdb¾ÍÔÙ´ÎʹÓÃÄã¸øÓèÇ°Ò»ÌõrunÃüÁîµÄ²ÎÊý£¬ÕâÊǺÜÓÐÓõġ£ÀûÓÃset args ÃüÁî¾Í¿ÉÒÔÐ޸ķ¢Ë͸ø³ÌÐòµÄ²ÎÊý£¬¶øʹÓÃshow args ÃüÁî¾Í¿ÉÒԲ鿴Æäȱʡ²ÎÊýµÄÁÐ±í¡£
£¨gdb£©set args –b –x
(gdb) show args
backtraceÃüÁîΪ¶ÑÕ»ÌṩÏòºó¸ú×Ù¹¦ÄÜ¡£
Backtrace ÃüÁî²úÉúÒ»ÕÅÁÐ±í£¬°üº¬×Å´Ó×î½üµÄ¹ý³Ì¿ªÊ¼µÄËùÒÔÓÐЧ¹ý³ÌºÍµ÷ÓÃÕâЩ¹ý³ÌµÄ²ÎÊý¡£
Èý£ºÏÔʾÊý¾Ý
* ÀûÓÃprint ÃüÁî¿ÉÒÔ¼ì²é¸÷¸ö±äÁ¿µÄÖµ¡£
(gdb) print p (pΪ±äÁ¿Ãû)
print ÊÇgdbµÄÒ»¸ö¹¦ÄܺÜÇ¿µÄÃüÁÀûÓÃËü¿ÉÒÔÏÔʾ±»µ÷ÊÔµÄÓïÑÔÖÐÈκÎÓÐЧµÄ±í´ïʽ¡£±í´ïʽ³ýÁË°üº¬Äã³ÌÐòÖеıäÁ¿Í⣬»¹¿ÉÒÔ°üº¬ÒÔÏÂÄÚÈÝ£º
1. ¶Ô³ÌÐòÖк¯ÊýµÄµ÷ÓÃ
(gdb) print find_entry(1,0)
2. Êý¾Ý½á¹¹ºÍÆäËû¸´ÔÓ¶ÔÏó
(gdb) print *table_start
$8={e=reference=’\000’,location=0x0,next=0x0}
3. ÖµµÄÀúÊ·³É·Ö
(gdb)print $1 ($1ΪÀúÊ·¼Ç¼±äÁ¿,ÔÚÒÔºó¿ÉÒÔÖ±½ÓÒýÓà $1 µÄÖµ)
4. ÈËΪÊý×é
ÈËΪÊý×éÌṩÁËÒ»ÖÖÈ¥ÏÔʾ´æ´¢Æ÷¿é£¨Êý×é½Ú»ò¶¯Ì¬·ÖÅäµÄ´æ´¢Çø£©ÄÚÈݵķ½·¨¡£ÔçÆڵĵ÷ÊÔ³ÌÐòûÓкܺõķ½·¨½«ÈÎÒâµÄÖ¸Õë»»³ÉÒ»¸öÊý×é¡£¾ÍÏñ¶Ô´ý²ÎÊýÒ»Ñù£¬ÈÃÎÒÃDz鿴ÄÚ´æÖÐÔÚ±äÁ¿hºóÃæµÄ10¸öÕûÊý£¬Ò»¸ö¶¯Ì¬Êý×éµÄÓï·¨ÈçÏÂËùʾ£º
b
Ïà¹ØÎĵµ£º
extern "C"
¡¡¡¡extern "C" °üº¬Ë«Öغ¬Ò壬´Ó×ÖÃæÉϼ´¿ÉµÃµ½£ºÊ×ÏÈ£¬±»ËüÐÞÊεÄÄ¿±êÊÇ“extern”µÄ£»Æä´Î£¬±»ËüÐÞÊεÄÄ¿±êÊÇ“C”µÄ¡£ÈÃÎÒÃÇÀ´Ïêϸ½â¶ÁÕâÁ½Öغ¬Òå¡£
¡¡¡¡£¨1£© ±»extern "C"ÏÞ¶¨µÄº¯Êý»ò±äÁ¿ÊÇexternÀàÐ͵ģ»
¡¡¡¡externÊÇC/C++ÓïÑÔÖбíÃ÷º¯ÊýºÍÈ«¾Ö±äÁ¿×÷Ó÷¶Î§£¨¿É¼ûÐÔ£©µÄ¹Ø¼ü×Ö£ ......
¼ÆËãÏß³ÌÖ´ÐÐijÏîÈÎÎñÏûºÄµÄʱ¼äʱ£¬Ðí¶à¿ª·¢ÈËÔ±»áµ÷ÓÃGetTickCount/GetTickCount64±àдÈçϵĴúÂ룺
// Get the current time (start time)
ULONGLONG qwStartTime = GetTickCount64();
// Perform complex algorithm here
// Subtract start time from current time to get duration
ULONGLONG dwElapsedTime = Get ......
Ç°Ãæ½²ÁËʹÓà ioctl·¢ËÍHCI CommandµÄ·½·¨¡£µ«HCI protocol»¹ÓÐһЩCommand£¬±ÈÈçInquiryµÈ£¬ËûÃÇÔò²»ÐèҪʹÓÃioctlÀ´·¢ËÍ¡£blueZ Ö±½ÓÌṩÁËÖ§³Ö£¬ËäÈ»ËûÃǵÄ×îÖÕ¶¼ÊÇÓÃͬÑù°ì·¨ÊµÏֵġ£
ÔÚÓ¦ÓóÌÐòÖУº
hci_inquiry(dev_id, length, num_rsp, NULL, &info, flags);
ÕâÑùÐèÒª°üº¬blueZ Í·ÎļþÈçÏ£º
#include //BT ......
SamÒ»ÄêÇ°ÔÚLinuxÏÂдÁËÒ»¸öÀàËÆWindowsÏÂBTWµÄ¿â--BTX¡£ÏÖÔÚÐèÒªÌí¼Óй¦ÄÜʱ·¢Ïֺܶà֪ʶµã¶¼Íü¼ÇÁË¡£ËùÒÔ¾ö¶¨ÔÚÕâ´ÎѧϰÖУ¬°ÑһЩbluez API¼Ç¼ÏÂÀ´¡£Õ⼸ÌìÓÖÏ룬ÕâÑù»¹²»¹»£¬²»Èç°ÑLinuxϵÄBluetooth±à³Ì»ù´¡¸ø¼Ç¼ÏÂÀ´°É¡£
Ç°ÑÔ£ºËæ×ÅǶÈëʽϵͳµÄ·ÉËÙ·¢Õ¹£¬ºÜ¶àǶÈëʽƽ̨ÉÏÐèÒªBluetoothÉ豸ºÍÓ¦Óᣵ«ÔÚLinuxÏ ......
1.Linux“Ï߳̔
½ø³ÌÓëÏß³ÌÖ®¼äÊÇÓÐÇø±ðµÄ£¬²»¹ýLinuxÄÚºËÖ»ÌṩÁËÇáÁ¿½ø³ÌµÄÖ§³Ö£¬Î´ÊµÏÖÏß³ÌÄ£ÐÍ¡£LinuxÊÇÒ»ÖÖ“¶à½ø³Ìµ¥Ï߳̔µÄ²Ù×÷ϵͳ¡£Linux±¾ÉíÖ»Óнø³ÌµÄ¸ÅÄ¶øÆäËùνµÄ“Ï߳̔±¾ÖÊÉÏÔÚÄÚºËÀïÈÔÈ»Êǽø³Ì¡£
´ó¼Ò ......