Re: Modification required in cout function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The reason is that is we want to check effect of cout on application booting.
Below is simple hello world program, It still call write() system
call. This may delay if
we have lots of cout in applications.
so we want that cout simply return without call of write().

strace ./a.out >&-
execve("./a.out", ["./a.out"], [/* 31 vars */]) = 0
brk                                   = 0x9cb6000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 1
fstat64(1, {st_mode=S_IFREG|0644, st_size=122592, ...}) = 0
mmap2(NULL, 122592, PROT_READ, MAP_PRIVATE, 1, 0) = 0xb80a9000
close(1)                                = 0
open("/lib/libc.so.6", O_RDONLY)        = 1
read(1, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0000\370K\0004\0\0\0000"...,
512) = 512
fstat64(1, {st_mode=S_IFREG|0755, st_size=1809640, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0xb80a8000
mmap2(0x4a9000, 1521232, PROT_READ|PROT_EXEC,
MAP_PRIVATE|MAP_DENYWRITE, 1, 0) = 0x4a9000
mmap2(0x617000, 12288, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 1, 0x16e) = 0x617000
mmap2(0x61a000, 9808, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x61a000
close(1)                                = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0xb80a7000
set_thread_area({entry_number:-1 -> 6, base_addr:0xb80a76c0,
limit:1048575, seg_32bit:1, contents:0, read_exec_only:0,
limit_in_pages:1, seg_not_present:0, useable:1}) = 0
mprotect(0x617000, 8192, PROT_READ)     = 0
mprotect(0x4a5000, 4096, PROT_READ)     = 0
munmap(0xb80a9000, 122592)              = 0
fstat64(1, 0xbfcc3480)                  = -1 EBADF (Bad file descriptor)
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0xb80c5000
write(1, "Hi"..., 2)                    = -1 EBADF (Bad file descriptor)
exit_group(2)                           = ?

On Fri, Jan 6, 2012 at 5:10 PM, naveen yadav <yad.naveen@xxxxxxxxx> wrote:
> Thanks for your suggestion.
>
> I am trying to comment the following line
>        new (&buf_cout) stdio_filebuf<char>(stdout, ios_base::out);
>        new (&buf_cin) stdio_filebuf<char>(stdin, ios_base::in);
>        new (&buf_cerr) stdio_filebuf<char>(stderr, ios_base::out);
> //        cout.rdbuf(&buf_cout);
>        cin.rdbuf(&buf_cin);
>        cerr.rdbuf(&buf_cerr);
>        clog.rdbuf(&buf_cerr);
>
> #ifdef _GLIBCXX_USE_WCHAR_T
>        new (&buf_wcout) stdio_filebuf<wchar_t>(stdout, ios_base::out);
>        new (&buf_wcin) stdio_filebuf<wchar_t>(stdin, ios_base::in);
>        new (&buf_wcerr) stdio_filebuf<wchar_t>(stderr, ios_base::out);
> //        wcout.rdbuf(&buf_wcout);
>        wcin.rdbuf(&buf_wcin);
>
>
> I am trying to comment at two places above. and building my gcc.
>
>
> Thanks
>
>
> On Fri, Jan 6, 2012 at 3:16 PM, Jonathan Wakely <jwakely.gcc@xxxxxxxxx> wrote:
>> On 6 January 2012 09:45, Jonathan Wakely wrote:
>>> On 6 January 2012 09:28, naveen yadav wrote:
>>>> Dear All,
>>>>
>>>> I want to modify cout source code in GCC such that it will not print
>>>> any thing on the screen.
>>>>
>>>> The reason is I have very large already compile code(distrubited in
>>>> lib form) and it is not possible to recompile. so i left with no
>>>> option but to modify in GCC code. Will you pls let me know where I can do it .
>>>
>>>
>>> Can't you just redirect the program's output to /dev/null when you run
>>> the program?
>>>
>>> Or close the file descriptor in your program's main() function?
>>>
>>> Or duplicate the file descriptor in main() to redirect the output to a file?
>>
>> Or replace std::cout's streambuf with a different streambuf that
>> doesn't write to stdout.
>>
>> I could probably think of more ways to do it without altering the
>> standard library.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux