debug ( ) 1) ( ) 2) ( ) assert, printf ( ) Japan Advanced Institute of Science and Technology

Similar documents
char char 1 signed char unsigned char ( ; single-quote 0x27) ASCII Japan Advanced Institute of Science and Technology

lexex.dvi

: CR (0x0d) LF (0x0a) line separator CR Mac LF UNIX CR+LF MS-DOS WINDOWS Japan Advanced Institute of Science and Technology

file"a" file"b" fp = fopen("a", "r"); while(fgets(line, BUFSIZ, fp)) {... fclose(fp); fp = fopen("b", "r"); while(fgets(line, BUFSIZ, fp)) {... fclose

r07.dvi

I117 II I117 PROGRAMMING PRACTICE II 2 SOFTWARE DEVELOPMENT ENV. 2 Research Center for Advanced Computing Infrastructure (RCACI) / Yasuhiro Ohara yasu

ohp07.dvi

C言語によるアルゴリズムとデータ構造

新・明解C言語 実践編

I 2 tutimura/ I 2 p.1/??

r08.dvi

I117 7 School of Information Science, Japan Advanced Institute of Science and Technology

mstrcpy char *mstrcpy(const char *src); mstrcpy malloc (main free ) stdio.h fgets char *fgets(char *s, int size, FILE *stream); s size ( )

第5回お試しアカウント付き並列プログラミング講習会

ohp08.dvi

I117 II I117 PROGRAMMING PRACTICE II SOFTWARE DEVELOPMENT ENV. 1 Research Center for Advanced Computing Infrastructure (RCACI) / Yasuhiro Ohara

(1/2) 2/45 HPC top runner application programmer PC-9801F N88-BASIC Quick BASIC + DOS ( ) BCB Windows Percolation, Event-driven MD ActionScript Flash

1 1.1 C 2 1 double a[ ][ ]; 1 3x x3 ( ) malloc() malloc 2 #include <stdio.h> #include

18 C ( ) hello world.c 1 #include <stdio.h> 2 3 main() 4 { 5 printf("hello World\n"); 6 } [ ] [ ] #include <stdio.h> % cc hello_world.c %./a.o

超初心者用

ohp03.dvi

I. Backus-Naur BNF : N N 0 N N N N N N 0, 1 BNF N N 0 11 (parse tree) 11 (1) (2) (3) (4) II. 0(0 101)* (

1 1.1 C 2 1 double a[ ][ ]; 1 3x x3 ( ) malloc() 2 double *a[ ]; double 1 malloc() dou

I httpd School of Information Science, Japan Advanced Institute of Science and Technology

Original : Hello World! (0x0xbfab85e0) Copy : Hello World! (0x0x804a050) fgets mstrcpy malloc mstrcpy (main ) mstrcpy malloc free fgets stream 1 ( \n

/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental structures /06/14(Tue) / Memory Management /06/1

(K&R 2.9) ~, &,, >>, << 2. (K&R 5.7) 3. (K&R 5.9) 4. (K&R 5.10) (argc argv atoi(), atof() ) 5. (K&R 7.5) (K&R 7.6) - FILE, stdin, stdout, std

II 3 yacc (2) 2005 : Yacc 0 ~nakai/ipp2 1 C main main 1 NULL NULL for 2 (a) Yacc 2 (b) 2 3 y

Taro-ポインタ変数Ⅰ(公開版).j

fl™‹ä1.eps

(2 Linux Mozilla [ ] [ ] [ ] [ ] URL 2 qkc, nkc ~/.cshrc (emacs 2 set path=($path /usr/meiji/pub/linux/bin tcsh b

C

slide5.pptx

橡Pro PDF

I. Backus-Naur BNF S + S S * S S x S +, *, x BNF S (parse tree) : * x + x x S * S x + S S S x x (1) * x x * x (2) * + x x x (3) + x * x + x x (4) * *


untitled

yacc.dvi

untitled

解きながら学ぶC言語

joho07-1.ppt

:30 12:00 I. I VI II. III. IV. a d V. VI

02: 変数と標準入出力

r03.dvi

double float

C 2 / 21 1 y = x 1.1 lagrange.c 1 / Laglange / 2 #include <stdio.h> 3 #include <math.h> 4 int main() 5 { 6 float x[10], y[10]; 7 float xx, pn, p; 8 in

:30 12:00 I. I VI II. III. IV. a d V. VI


ex01.dvi

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裵²ó ¨¡ À©¸æ¹½Â¤¡§¾ò·ïʬ´ô ¨¡

8 / 0 1 i++ i 1 i-- i C !!! C 2

Microsoft Word - C.....u.K...doc

273? C

I void* School of Information Science, Japan Advanced Institute of Science and Technology

広報さがみはら第1242号

新版明解C言語 実践編

1-4 int a; std::cin >> a; std::cout << "a = " << a << std::endl; C++( 1-4 ) stdio.h iostream iostream.h C++ include.h 1-4 scanf() std::cin >>

void hash1_init(int *array) int i; for (i = 0; i < HASHSIZE; i++) array[i] = EMPTY; /* i EMPTY */ void hash1_insert(int *array, int n) if (n < 0 n >=

GNU Emacs GNU Emacs

PC Windows 95, Windows 98, Windows NT, Windows 2000, MS-DOS, UNIX CPU

O(N) ( ) log 2 N

double 2 std::cin, std::cout 1.2 C fopen() fclose() C++ std::fstream 1-3 #include <fstream> std::fstream fout; int a = 123; fout.open( "data.t

ex14.dvi

‚æ2›ñ C„¾„ê‡Ìš|

C ( ) C ( ) C C C C C 1 Fortran Character*72 name Integer age Real income 3 1 C mandata mandata ( ) name age income mandata ( ) mandat

2 2 3 dbxtool dbx (GUI) dbxtool dbx C++ Oracle Solaris Studio 12.2 examples/debugger/debug_tutorial 1. cp -r /opt/solstudio12.2/examples/de

Minimum C Minimum C Minimum C BNF T okenseq W hite Any D

C B

II ( ) prog8-1.c s1542h017%./prog8-1 1 => 35 Hiroshi 2 => 23 Koji 3 => 67 Satoshi 4 => 87 Junko 5 => 64 Ichiro 6 => 89 Mari 7 => 73 D

1.ppt

tuat2.dvi

XMPによる並列化実装2

バイオプログラミング第 1 榊原康文 佐藤健吾 慶應義塾大学理工学部生命情報学科

ex01.dvi

LAN Copyright c Daikoku Manabu This tutorial is licensed under a Creative Commons Attribution 2.1 Japan License

memo

1 C STL(1) C C C libc C C C++ STL(Standard Template Library ) libc libc C++ C STL libc STL iostream Algorithm libc STL string vector l

untitled

( ) ( ) lex LL(1) LL(1)

() / (front end) (back end) (phase) (pass) 1 2

Taro-リストⅢ(公開版).jtd

C C UNIX C ( ) 4 1 HTML 1

1) OOP 2) ( ) 3.2) printf Number3-2.cpp #include <stdio.h> class Number Number(); // ~Number(); // void setnumber(float n); float getnumber();

Microsoft Word - 【第5分科会】ConcolicTestingグループ_付録_修正_ doc

program.dvi

スライド 1

(300, 150) 120 getchar() HgBox(x, y, w, h) (x, y), w, h #include <stdio.h> #include <handy.h> int main(void) { int i; double w, h; } HgO

Taro-再帰関数Ⅱ(公開版).jtd

< F2D837C E95CF CF68A4A94C5816A2E6A>

/* do-while */ #include <stdio.h> #include <math.h> int main(void) double val1, val2, arith_mean, geo_mean; printf( \n ); do printf( ); scanf( %lf, &v

pptx

卒 業 研 究 報 告.PDF

AutoTuned-RB

問 2 ( 型変換 ) 次のプログラムを実行しても正しい結果が得られない 何が間違いかを指摘し 正しく修正せよ ただし int サイズが 2 バイト long サイズが 4 バイトの処理系での演算を仮定する #include <stdio.h> int main( void ) { int a =

A/B (2018/06/08) Ver kurino/2018/soft/soft.html A/B

A/B (2018/10/19) Ver kurino/2018/soft/soft.html A/B

cpp1.dvi

PowerPoint プレゼンテーション - 物理学情報処理演習

3.1 stdio.h iostream List.2 using namespace std C printf ( ) %d %f %s %d C++ cout cout List.2 Hello World! cout << float a = 1.2f; int b = 3; cout <<

Microsoft PowerPoint - lec10.ppt

Transcription:

I117 28 School of Information Science, Japan Advanced Institute of Science and Technology

debug ( ) 1) ( ) 2) ( ) assert, printf ( ) Japan Advanced Institute of Science and Technology 2008 1-2 1

a) b) -g b) Japan Advanced Institute of Science and Technology 2008 1-2 2

#include <stdio.h> #include <stdlib.h> int main() { printf("%s\n", 32); } % cc -g a4.c % dbx./a.out help changes.dbxrc dbxenv suppr a.out ld.so.1 Japan Advanced Institute of Science and Technology 2008 1-2 3

libc.so.1 libdl.so.1 libc_psr.so.1 (dbx) run : a.out ( id 21296) SEGV ( ) 0xff2b455c: strlen+0x0080: ld [%o1], %o2 :main 4 printf("%s\n", 32); (dbx) 4 dbx exit quit

% limit coredumpsize unlimit % rm -f core % cc -g a4.c %./a.out (core ) core dbx % dbx./a.out core ( ) a.out Japan Advanced Institute of Science and Technology 2008 1-2 5

core ( ) SEGV ( 0xff2b455c: strlen+0x0080: ld [%o1], %o2 :main 4 printf("%s\n", 32); (dbx) 4

(cont.) #include <stdio.h> int sub(char *msg) { msg[123456]= X ; } int main() { sub("abc"); } % cc -g a5.c %./a.out (core ) Japan Advanced Institute of Science and Technology 2008 1-2 7

(cont.) % dbx./a.out core ( ) SEGV ( :sub 3 msg[123456]= X ; (dbx) print msg msg = 0x20dd8 "abc" (dbx) print msg[123456] dbx: 0x3f018 Japan Advanced Institute of Science and Technology 2008 1-2 8

(cont.) (dbx) where =>[1] sub(msg = 0x20dd8 "abc"), 3 "a5.c" [2] main(), 6 "a5.c" (dbx) up :main 6 sub("abc"); (dbx) list 1,10 1 #include <stdio.h> 2 int sub(char *msg) { Japan Advanced Institute of Science and Technology 2008 1-2 9

(cont.) 3 msg[123456]= X ; 4 } 5 int main() { 6 sub("abc"); 7 } Japan Advanced Institute of Science and Technology 2008 1-2 10

a) b) c) d) Solaris watchmalloc Japan Advanced Institute of Science and Technology 2008 1-2 11

watchmalloc LD PRELOAD MALLOC DEBUG LD_PRELOAD=watchmalloc.so.1 export LD_PRELOAD MALLOC_DEBUG=WATCH export MALLOC_DEBUG./a.out Japan Advanced Institute of Science and Technology 2008 1-2 12

free (2 free) #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char *x=null; x = malloc(5); strcpy(x, "ABC"); free(x); free(x); } Japan Advanced Institute of Science and Technology 2008 1-2 13

free (cont.) % cc -g a.c %./a.out %./X.sh - (watchmalloc ) % dbx./a.out core ( ) Japan Advanced Institute of Science and Technology 2008 1-2 14

free (cont.) watchmalloc.so.1 ( ) TRAP ( 0xff3813b0: realfree+0x0044: st % :main 9 free(x); (dbx) 9 free Japan Advanced Institute of Science and Technology 2008 1-2 15

#include <stdlib.h> int main() { char **x=null; x = malloc(sizeof(char*)*5); free(x[2]); } % cc -g a3.c %./a.out %./X.sh - Japan Advanced Institute of Science and Technology 2008 1-2 16

(cont.) % dbx./a.out core SEGV ( 0xff381390: realfree+0x0024: ld [ :main 5 free(x[2]); (dbx) print x[2] x[2] = 0xbaddcafe "< 0xbaddcafe>" watachmalloc malloc 0xbaddcafe Japan Advanced Institute of Science and Technology 2008 1-2 17

MALLOC OPTIONS MALLOC CHECK Electrict Fence ; D.U.M.A valgrind Japan Advanced Institute of Science and Technology 2008 1-2 18

assert printf Japan Advanced Institute of Science and Technology 2008 1-2 19

assert ( ) assert.h #include <stdio.h> #include <assert.h> int main() { int x; x=17; assert(x<9); } Japan Advanced Institute of Science and Technology 2008 1-2 20

assert (cont.) % cc -g a6.c %./a.out Assertion failed: x<9, file a6.c, line 6 (core ) 6 NDEBUG % cc -g -DNDEBUG a6.c %./a.out Japan Advanced Institute of Science and Technology 2008 1-2 21

printf printf printf("x %d", x); fflush printf("x %d", x); fflush(stdout); Japan Advanced Institute of Science and Technology 2008 1-2 22

FILE LINE #include <stdio.h> int main() { char *x; printf("%s:%d\n", FILE, LINE ); x++; printf("%s:%d\n", FILE, LINE ); printf(x); printf("%s:%d\n", FILE, LINE ); } Japan Advanced Institute of Science and Technology 2008 1-2 23

(cont.) % cc b1.c %./a.out b1.c:4 b1.c:6 (core ) 6 7 Japan Advanced Institute of Science and Technology 2008 1-2 24

(cont.) C99 func #include <stdio.h> int a() { printf("%s:%d %s\n", FILE, LINE, func ); } int main() { printf("%s:%d\n", FILE, LINE ); a(); } Japan Advanced Institute of Science and Technology 2008 1-2 25

(cont.) % cc b2b.c ;./a.out b2b.c:7 b2b.c:3 a % gcc b2b.c ;./a.out b2b.c:7 b2b.c:3 a FUNCTION Japan Advanced Institute of Science and Technology 2008 1-2 26

syslog UNIX syslog... #include <syslog.h>... syslog(log_info, "x %d", x);... /var/log/message Japan Advanced Institute of Science and Technology 2008 1-2 27

16 Japan Advanced Institute of Science and Technology 2008 1-2 28

lint % lint b1.c (5) : : x (9) : return : main (9) main printf Japan Advanced Institute of Science and Technology 2008 1-2 29

gcc -Wall gcc lint % cat a4.c #include <stdio.h> #include <stdlib.h> int main() { printf("%s\n", 32); } % gcc -Wall a4.c a4.c: In function main : a4.c:4: : format %s expects type char *, but argument 2 has type int a4.c:5: : control reaches end of non-void function Japan Advanced Institute of Science and Technology 2008 1-2 30