TRUEANGLE

LEARNING PROCESS

Tracing, Bit Manipulation Without Branching

Breakpoint 1, main () at set-or-clear-bits-without-branching.c:11
11     printf("Enter the word to modify ");
(gdb) next
12    scanf("%u",&w);
(gdb) next
Enter the word to modify 6
14     printf("Enter the bit mask ");
(gdb) next
15     scanf("%u",&m);
(gdb) next
Enter the bit mask 3
21    w = (w & ~m) | (-f & m); 
(gdb) print w
$1 = 6
(gdb) print m
$2 = 3
(gdb) print ~m
$3 = 4294967292
(gdb) print *~m
Cannot access memory at address 0xfffffffc
(gdb) print ~m
$4 = 4294967292
(gdb) print f
$5 = 0
(gdb) print -f
$6 = 0
(gdb) print +f
$7 = 0
(gdb) print -f
$8 = 0
(gdb) print (w & ~m)
$9 = 4
(gdb) p/t (w & ~m)
$10 = 100
(gdb) p/t w
$11 = 110
(gdb) p/t m
$12 = 11
(gdb) p/t ~m
$13 = 11111111111111111111111111111100
(gdb) p/t (w & ~m)
$14 = 100
(gdb) print w
$15 = 6
(gdb) p/t 6
$16 = 110
(gdb) p/t 4
$17 = 100
(gdb) p/t (-f & m)
$18 = 0
(gdb) p/t -f
$19 = 0
(gdb) p/t m
$20 = 11
(gdb) next
23    printf("Modified value is %u \n",w);
(gdb) next
Modified value is 4 
25    return 0;
(gdb) next
26    }
(gdb) next
__libc_start_main (main=0x40056d 
, argc=1, argv=0x7fffffffe2c8, init=, fini=, rtld_fini=, stack_end=0x7fffffffe2b8) at libc-start.c:321 321 libc-start.c: No such file or directory. (gdb) next [Inferior 1 (process 5753) exited normally] (gdb)

And Operations Using C

Breakpoint 1, main () at and-p2.c:5
5     int val1 = 4;
(gdb) next
6     int val2 = 0;
(gdb) next
8     if ( val1 & val2)
(gdb) print val1
$1 = 4
(gdb) print val2
$2 = 0
(gdb) print (val1 & val2)
$3 = 0
(gdb) print (3 & 1)
$4 = 1
(gdb) next
11    if ( val1 && val2 )
(gdb) print (val1 && val2)
$5 = 0
(gdb) next
13  }
(gdb) next
__libc_start_main (main=0x4004fd 
, argc=1, argv=0x7fffffffe328, init=, fini=, rtld_fini=, stack_end=0x7fffffffe318) at libc-start.c:321 321 libc-start.c: No such file or directory. (gdb) next [Inferior 1 (process 5234) exited normally] (gdb) quit $

IPC Pipes Internal

Breakpoint 1, main () at popen1-p1.c:10
10    memset(buffer,'\0',sizeof(buffer));
(gdb) next
11    read_fp = popen("uname -a","r");
(gdb) print read_fp
$1 = (FILE *) 0x0
(gdb) next
12    if (read_fp != NULL)
(gdb) print read_fp
$2 = (FILE *) 0x601010
(gdb) print (char *)read_fp
$3 = 0x601010 "\210$\255", 
(gdb) next
14        chars_read = fread(buffer,sizeof(char),BUFSIZ,read_fp);
(gdb) print chars_read
$4 = 32767
(gdb) next
15        if (chars_read > 0) {
(gdb) print chars_read
$5 = 79
(gdb) next
16      printf("Output was:- \n%s\n",buffer);
(gdb) next
Output was:- 
Linux debian 3.12-1-amd64 #1 SMP Debian 3.12.9-1 (2014-02-01) x86_64 GNU/Linux

18        pclose(read_fp);
(gdb) next
19        exit(EXIT_SUCCESS);
(gdb) next
[Inferior 1 (process 5508) exited normally]
(gdb) 

Questioning Popen Function

Breakpoint 1, main () at popen1-p2.c:10
10    memset(buffer,'\0',sizeof(buffer));
(gdb) next
11    read_fp = popen("stat","r");
(gdb) print read_fp
$1 = (FILE *) 0x0
(gdb) next
12    if (read_fp != NULL)
(gdb) stat: missing operand
Try 'stat --help' for more information.

14        chars_read = fread(buffer,sizeof(char),BUFSIZ,read_fp);
(gdb) print read_fp
$2 = (FILE *) 0x601010
(gdb) print chars_read
$3 = 32767
(gdb) next
15        if (chars_read > 0) {
(gdb) next
18        pclose(read_fp);
(gdb) print chars_read
$4 = 0
(gdb) print *read_fp
$5 = {_flags = -72538984, _IO_read_ptr = 0x7ffff7ff7000 "", _IO_read_end = 0x7ffff7ff7000 "", 
  _IO_read_base = 0x7ffff7ff7000 "", _IO_write_base = 0x7ffff7ff7000 "", _IO_write_ptr = 0x7ffff7ff7000 "", 
  _IO_write_end = 0x7ffff7ff7000 "", _IO_buf_base = 0x7ffff7ff7000 "", 
  _IO_buf_end = 0x7ffff7ff8000 "P\200\377\367\377\177", _IO_save_base = 0x0, _IO_backup_base = 0x0, 
  _IO_save_end = 0x0, _markers = 0x0, _chain = 0x7ffff7dd8060 <_IO_2_1_stderr_>, _fileno = 7, _flags2 = 0, 
  _old_offset = 0, _cur_column = 0, _vtable_offset = 0 '\000', _shortbuf = "", _lock = 0x601100, 
  _offset = -1, __pad1 = 0x0, __pad2 = 0xffffffffffffffff, __pad3 = 0x0, __pad4 = 0x0, __pad5 = 0, 
  _mode = -1, _unused2 = '\000' }
(gdb) next
19        exit(EXIT_SUCCESS);
(gdb) next
[Inferior 1 (process 5284) exited normally]
(gdb) 

Posix Thread Internal

Breakpoint 1, main () at thread1-p2.c:15
15    res = pthread_create(&a_thread,NULL,thread_function,(void *)message);
(gdb) print res
$1 = 0
(gdb) next
[New Thread 0x7ffff7816700 (LWP 6689)]
17    printf("Waiting for thread to finish...\n");
(gdb) print res
$2 = 0
(gdb) next
Thread function is running. Argument was  Hello World
Waiting for thread to finish...
18    res = pthread_join(a_thread,&thread_result);
(gdb) l
13    pthread_t a_thread;
14    void *thread_result;
15    res = pthread_create(&a_thread,NULL,thread_function,(void *)message);
16  
17    printf("Waiting for thread to finish...\n");
18    res = pthread_join(a_thread,&thread_result);
19  
20    printf("Thread joined, it returned %s \n",(char *)thread_result);
21    printf("Message is now %s \n",message);
22    exit(EXIT_SUCCESS);
(gdb) next
[Thread 0x7ffff7816700 (LWP 6689) exited]
20    printf("Thread joined, it returned %s \n",(char *)thread_result);
(gdb) next
Thread joined, it returned Thank you for the CPU time 
21    printf("Message is now %s \n",message);
(gdb) next
Message is now Bye! 
22    exit(EXIT_SUCCESS);
(gdb) next
[Inferior 1 (process 6685) exited normally]
(gdb) next
The program is not being run.
(gdb) 

Simple Signal Internals

Reading symbols from /home/jeffrin/beautifulwork-programmingpractice/processes-and-signals/a.out...done.
(gdb) break 1
Breakpoint 1 at 0x4005d8: file crtlc1-p1.c, line 1.
(gdb) r
Starting program: /home/jeffrin/beautifulwork-programmingpractice/processes-and-signals/a.out 
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
Hello world 
Hello world 
Hello world 
Hello world 
^C
Program received signal SIGINT, Interrupt.
0x00007ffff7aeb080 in __nanosleep_nocancel () at ../sysdeps/unix/syscall-template.S:81
81  ../sysdeps/unix/syscall-template.S: No such file or directory.
(gdb) l
76  in ../sysdeps/unix/syscall-template.S
(gdb) l
76  in ../sysdeps/unix/syscall-template.S
(gdb) next
__sleep (seconds=0) at ../sysdeps/unix/sysv/linux/sleep.c:142
142 ../sysdeps/unix/sysv/linux/sleep.c: No such file or directory.
(gdb) next
55  in ../sysdeps/unix/sysv/linux/sleep.c
(gdb) next
147 in ../sysdeps/unix/sysv/linux/sleep.c
(gdb) next
main () at crtlc1-p1.c:21
21      }
(gdb) next
19        printf("Hello world \n");
(gdb) next
Hello world 
20        sleep(1);
(gdb) next
21      }
(gdb) next
19        printf("Hello world \n");
(gdb) next
Hello world 
20        sleep(1);
(gdb) next
21      }
(gdb) next
19        printf("Hello world \n");
(gdb) signal SIGINT
Continuing with signal SIGINT.

Breakpoint 1, ouch (sig=2) at crtlc1-p1.c:8
8     printf("i got a signal %d\n",sig);
(gdb) next
i got a signal 2
9     (void) signal(SIGINT, SIG_DFL);
(gdb) next
10  }
(gdb) next
main () at crtlc1-p1.c:19
19        printf("Hello world \n");
(gdb) next
Hello world 
20        sleep(1);
(gdb) next
21      }
(gdb) signal SIGINT
Continuing with signal SIGINT.

Program terminated with signal SIGINT, Interrupt.
The program no longer exists.
(gdb) 



Internals Related to Malloc


Breakpoint 1, main () at memory1-p1.c:9
9     int megabyte = A_MEGABYTE;
(gdb) next
10    int exit_code = EXIT_FAILURE;
(gdb) print EXIT_FAILURE
No symbol "EXIT_FAILURE" in current context.
(gdb) printf EXIT_FAILURE
Bad format string, missing '"'.
(gdb) print exit_code
$1 = 0
(gdb) next
12    some_memory = (char *)malloc(megabyte);
(gdb) next
13    if (some_memory != NULL) {
(gdb) print some_memory
$2 = 0x7ffff7eda010 ""
(gdb) next
14      sprintf(some_memory,"Hello World\n");
(gdb) print some_memory
$3 = 0x7ffff7eda010 ""
(gdb) next
15      printf("%s",some_memory);
(gdb) print some_memory
$4 = 0x7ffff7eda010 "Hello World\n"
(gdb) next
Hello World
16      exit_code = EXIT_SUCCESS;
(gdb) print exit_code
$5 = 1
(gdb) next
18    exit(exit_code);
(gdb) next
[Inferior 1 (process 4249) exited normally]
(gdb) print exit_code
No symbol "exit_code" in current context.
(gdb) 

Simple Debug of a Python Program

$python -m pdb bubblesort-unsure.py 
> /home/jeffrin/beautifulwork-sorting/python/bubblesort-unsure.py(1)()
-> array_size = 10;
(Pdb) help

Documented commands (type help ):
========================================
EOF    bt         cont      enable  jump  pp       run      unt   
a      c          continue  exit    l     q        s        until 
alias  cl         d         h       list  quit     step     up    
args   clear      debug     help    n     r        tbreak   w     
b      commands   disable   ignore  next  restart  u        whatis
break  condition  down      j       p     return   unalias  where 

Miscellaneous help topics:
==========================
exec  pdb

Undocumented commands:
======================
retval  rv

(Pdb) break 1
Breakpoint 1 at /home/jeffrin/beautifulwork-sorting/python/bubblesort-unsure.py:1
(Pdb) next
> /home/jeffrin/beautifulwork-sorting/python/bubblesort-unsure.py(3)()
-> import random
(Pdb) next
> /home/jeffrin/beautifulwork-sorting/python/bubblesort-unsure.py(4)()
-> result = []
(Pdb) print result
*** NameError: name 'result' is not defined
(Pdb) print result[]
*** SyntaxError: invalid syntax (, line 1)
(Pdb) print result[0]
*** NameError: name 'result' is not defined
(Pdb) next
> /home/jeffrin/beautifulwork-sorting/python/bubblesort-unsure.py(10)()
-> for x in range (0, 10):
(Pdb) next
> /home/jeffrin/beautifulwork-sorting/python/bubblesort-unsure.py(11)()
-> num = random.randint(0, 10)
(Pdb) print x
0
(Pdb) next
> /home/jeffrin/beautifulwork-sorting/python/bubblesort-unsure.py(12)()
-> while num in result:
(Pdb) print num
3
(Pdb) next
> /home/jeffrin/beautifulwork-sorting/python/bubblesort-unsure.py(14)()
-> result.append(num)
(Pdb) next
> /home/jeffrin/beautifulwork-sorting/python/bubblesort-unsure.py(10)()
-> for x in range (0, 10):
(Pdb) print result
[3]
(Pdb) next
> /home/jeffrin/beautifulwork-sorting/python/bubblesort-unsure.py(11)()
-> num = random.randint(0, 10)
(Pdb) quit
$

Good News

It is in living and acting that man establishes his relationship with being, with the truth and with the good. The artist has a special relationship to beauty. In a very true sense it can be said that beauty is the vocation bestowed on him by the Creator in the gift of artistic talent. And, certainly, this too is a talent which ought to be made to bear fruit, in keeping with the sense of the Gospel parable of the talents (cf. Mt 25:14-30).

Here we touch on an essential point. Those who perceive in themselves this kind of divine spark which is the artistic vocationas poet, writer, sculptor, architect, musician, actor and so onfeel at the same time the obligation not to waste this talent but to develop it, in order to put it at the service of their neighbour and of humanity as a whole.

John Paul II Letter to Artists, (April 4, 1999) The artistic vocation in the service of beauty