강의10

Similar documents
Microsoft PowerPoint - System Programming Lab Week1.ppt [호환 모드]

6주차.key

MPLAB C18 C

hlogin2

vi 사용법

Sena Technologies, Inc. HelloDevice Super 1.1.0

MAX+plus II Getting Started - 무작정따라하기

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

hlogin7

gdb 사용법 Debugging Debug라는말은 bug를없앤다는말이다. Bug란, 컴퓨터프로그램상의논리적오류를말하며, 이것을찾아해결하는과정이바로, debugging이다. 초기컴퓨터들은실제벌레가컴퓨터에들어가서오작동을일으키는경우가있었다고하며, 여기서 debug 이라는말이

Deok9_Exploit Technique

PRO1_09E [읽기 전용]

SRC PLUS 제어기 MANUAL

Microsoft Word - FunctionCall

02 C h a p t e r Java

13주-14주proc.PDF

4. #include <stdio.h> #include <stdlib.h> int main() { functiona(); } void functiona() { printf("hihi\n"); } warning: conflicting types for functiona


untitled

Microsoft Word - ExecutionStack

휠세미나3 ver0.4

PRO1_02E [읽기 전용]

초보자를 위한 C++

김기남_ATDC2016_160620_[키노트].key

PCServerMgmt7

untitled

Poison null byte Excuse the ads! We need some help to keep our site up. List 1 Conditions 2 Exploit plan 2.1 chunksize(p)!= prev_size (next_chunk(p) 3

The_IDA_Pro_Book

Microsoft PowerPoint - 15-MARS

INTRO Basic architecture of modern computers Basic and most used assembly instructions on x86 Installing an assembly compiler and RE tools Practice co

Something that can be seen, touched or otherwise sensed

example code are examined in this stage The low pressure pressurizer reactor trip module of the Plant Protection System was programmed as subject for

APOGEE Insight_KR_Base_3P11

PowerPoint 프레젠테이션

chapter4

대학교육151호-합침

PowerPoint 프레젠테이션

목차 BUG offline replicator 에서유효하지않은로그를읽을경우비정상종료할수있다... 3 BUG 각 partition 이서로다른 tablespace 를가지고, column type 이 CLOB 이며, 해당 table 을 truncate

Chap06(Interprocess Communication).PDF

Microsoft PowerPoint APUE(Intro).ppt

untitled

DE1-SoC Board

No Slide Title

untitled

K&R2 Reference Manual 번역본

ABC 11장

PowerPoint 프레젠테이션

Interstage5 SOAP서비스 설정 가이드

Microsoft PowerPoint - chap6 [호환 모드]

IDA 5.x Manual hwp

,,,,,, (41) ( e f f e c t ), ( c u r r e n t ) ( p o t e n t i a l difference),, ( r e s i s t a n c e ) 2,,,,,,,, (41), (42) (42) ( 41) (Ohm s law),

03장.스택.key

C# Programming Guide - Types

untitled

chap10.PDF

C++-¿Ïº®Çؼ³10Àå

/chroot/lib/ /chroot/etc/

본 강의에 들어가기 전

(Asynchronous Mode) ( 1, 5~8, 1~2) & (Parity) 1 ; * S erial Port (BIOS INT 14H) - 1 -

Microsoft PowerPoint - PL_03-04.pptx

목차 BUG 문법에맞지않는질의문수행시, 에러메시지에질의문의일부만보여주는문제를수정합니다... 3 BUG ROUND, TRUNC 함수에서 DATE 포맷 IW 를추가지원합니다... 5 BUG ROLLUP/CUBE 절을포함하는질의는 SUBQUE

PowerPoint 프레젠테이션


歯9장.PDF

untitled

슬라이드 제목 없음

예제 1.1 ( 관계연산자 ) >> A=1:9, B=9-A A = B = >> tf = A>4 % 4 보다큰 A 의원소들을찾을경우 tf = >> tf = (A==B) % A

chap7.key

Chap04(Signals and Sessions).PDF

컴파일러

Microsoft PowerPoint - o8.pptx

PowerPoint 프레젠테이션

歯sql_tuning2

Microsoft PowerPoint - 기계공학실험1-1MATLAB_개요2D.pptx

구문 분석

Microsoft Word - Network Programming_NewVersion_01_.docx

A Dynamic Grid Services Deployment Mechanism for On-Demand Resource Provisioning

No Slide Title


untitled

슬라이드 1

<313020C1A4BFECBAC034332E687770>

10주차.key

Modern Javascript

<C0CCBCBCBFB52DC1A4B4EBBFF82DBCAEBBE7B3EDB9AE2D D382E687770>

2

교육지원 IT시스템 선진화

Week3

화판_미용성형시술 정보집.0305

2. GCC Assembler와 AVR Assembler의차이 A. GCC Assembler 를사용하는경우 i. Assembly Language Program은.S Extension 을갖는다. ii. C Language Program은.c Extension 을갖는다.

슬라이드 1

01Àå

학번 : 이름 : 1. 다음파일트리구조를가진유닉스시스템이있다고가정하자. / /bin/ /home/ /home/taesoo/ /usr/ /usr/lib/ /usr/local/lib /media 모든폴더에파일이하나도없다고가정했을때사용자가터미널에서다음 ls 명령입력시화면출력

fx-82EX_fx-85EX_fx-350EX

歯처리.PDF

Week5

10.

歯7장.PDF

chap7.PDF

Transcription:

Computer Programming gdb and awk 12 th Lecture 김현철컴퓨터공학부서울대학교

순서 C Compiler and Linker 보충 Static vs Shared Libraries ( 계속 ) gdb awk Q&A

Shared vs Static Libraries ( 계속 ) Advantage of Using Libraries Reduced Complexity of Managing Projects Advantages of Using Shared Libraries Reduced Size of Each Executable File Easy Library-Functions Replacement Disadvantage of Using Shared Libraries Dynamic Linking Overhead

gdb 기본 Features Run a Program Stop Execution within the Program Examine and Change Variables during Execution Trace How the Program Executes Provide Command-Line Editing and History Features

Using gdb Compilation with the g Option Generate an Expanded Symbol Table for Use with gdb martini:~$ gcc g main.c func.o Execution of gdb Permit Debugging a Program Compiled with the g Option Permit Discovering Where and Why the Program Failed (with a Core Dump) martini:~$ gdb a.out martini:~$ gdb a.out core Core dump: copy of memory image; run ulimit c unlimited to make the size unlimited

gdb Basic Commands help: Print a List of Commands or Topics run: Execute the Program quit: Exit gdb (gdb) help List of classes of commands (omitted) running -- Running the program (gdb) help running run -- Start debugged program Argument list (gdb) run 1 (gdb) quit [Ctrl]-C to stop the program

gdb Example /* test.c */ struct { int *i_p; } s; void foo() { *(s.i_p) = 2; printf("s.i = %d\n", *(s.i_p)); } main(int argc, char *argv[]){ int *i_p; *i_p = atoi(argv[1]); printf("i = %d\n", *i_p); foo(); } martini:~$ gcc g test.c martini:~$ a.out 1 i = 1 세그멘테이션오류 (core dumped)

gdb Example ( 계속 ) list: Show the Lines Surrounding the Code Just Executed whatis: Print the Type of a Variable or Function ptype: Show the Contents of a Data Type martini:~$ gdb a.out core (omitted) Program terminated with signal 11, Segmentation fault. #0 0x0804846b in foo () at test.c:6 6 *(s.i_p) = 2; (gdb) list 6 *(s.i_p) = 2; (gdb) whatis s type = struct {...} (gdb) ptype s type = struct { int *i_p; } Line number more powerful than whatis Call stack number 0: most recent

gdb Example ( 계속 ) print: Print the Value of a Variable or Expression up/down: Move Up/Down the Stack Frame to Make another Function the Current One (gdb) print s print func() possible $1 = {i_p = 0x0} (gdb) print s.i_p Value history identifiers $2 = (int *) 0x0 The error occurred at *(s.i_p) = 2; (gdb) print *(s.i_p) Cannot access memory at address 0x0 (gdb) up #1 0x080484c9 in main (argc=2, argv=0xbffffce4) at test.c:15 15 foo(); (gdb) print i_p $3 = (int *) 0xbffffc98 (gdb) print *i_p $4 = 1 (gdb) print $4+1 $5 = 2

gdb Example ( 계속 ) backtrace/where: Print the Current Location and a Stack Trace set variable: Assign a Value to a Variable print: Print the Assigned Value martini:~$ gdb a.out (omitted) (gdb) run 1 Program received signal SIGSEGV, Segmentation fault. 0x0804846b in foo () at test.c:6 6 *(s.i_p) = 2; (gdb) backtrace #0 0x0804846b in foo () at test.c:6 #1 0x080484c9 in main (argc=2, argv=0xbffffcb4) at test.c:15 (gdb) up #1 0x080484c9 in main (argc=2, argv=0xbffffcb4) at test.c:15 15 foo(); (gdb) set variable (*i_p)++ (gdb) print *i_p += 1 $1 = 3 same as where Assignments do not work with core

gdb Example ( 계속 ) break: Set Breakpoints in the Program watch: Set Break-If Breakpoints info breakpoints: Show All Breakpoints and Watchpoints martini:~$ gdb a.out (omitted) (gdb) break foo Breakpoint 1 at 0x8048466: file test.c, line 6. (gdb) break test.c:6 Note: breakpoint 1 also set at pc 0x8048466. Breakpoint 2 at 0x8048466: file test.c, line 6. (gdb) run 1 Breakpoint 1, foo () at test.c:6 6 *(s.i_p) = 2; (gdb) watch *i_p > 0 Hardware watchpoint 3: *i_p > 0 (gdb) info breakpoints (omitted) 5 void foo() { 6 *(s.i_p) = 2;

gdb Example ( 계속 ) kill: Abort the Running Process delete: Delete a Breakpoint or a Watchpoint next: Execute the Next Line, Executing a Function (gdb) kill Kill the program being debugged? (y or n) y (gdb) delete 2 9 (omitted) (gdb) delete 1 10 main() (gdb) break 11 11 Int *i_p; Breakpoint 4 at 0x8048495: file test.c, line 11. 12 (gdb) run 1 Breakpoint 1, main (argc=2, argv=0xbffffcb4) at test.c:12 12 *i_p = atoi(argv[1]); (gdb) print *i_p $1 = -1073742712 (gdb) next 13 printf("i = %d\n", *i_p); (gdb) print *i_p $2 = 1

gdb Example ( 계속 ) step: Execute the Next Line, Stepping into a Function continue: Continue Execution (gdb) kill Kill the program being debugged? (y or n) y (gdb) run 1 (omitted) (gdb) step 13 printf("i = %d\n", *i_p); (gdb) step i = 1 15 foo(); (gdb) step foo () at test.c:6 6 *(s.i_p) = 2; (gdb) continue

gdb Example ( 계속 ) info line: Show Where the Object Code Begins and Ends disassemble: Produce a Machine Listing info registers: List Integer Registers and Their Contents (gdb) kill Kill the program being debugged? (y or n) y (gdb) run 1 (omitted) (gdb) info line 12 Line 12 of "test.c" starts at address 0x8048495 <main+9> and ends at 0x80484af <main+35>. (gdb) disassemble main (gdb) x 0x80484ca 0x80484ca <main+62>: ret 0x80484ca <main+62>: 0x895590c3 (gdb) info registers

awk (Aho Weinberger Kernighan) PL for Computing and Data-Manipulation Tasks (Especially, Columns of Data) Example EXECUTION TIME = 2.0 EXECUTION TIME = 4.2 martini:~$ awk {sum = sum + $4} END {print "avg = " sum/nr} temp martini:~$ awk f avg.awk temp