public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Modification required in cout function
@ 2012-01-06  9:28 naveen yadav
  2012-01-06  9:46 ` naveen yadav
  2012-01-06  9:46 ` Jonathan Wakely
  0 siblings, 2 replies; 11+ messages in thread
From: naveen yadav @ 2012-01-06  9:28 UTC (permalink / raw)
  To: gcc-help, gcc-help

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 .

Thanks

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Modification required in cout function
  2012-01-06  9:28 Modification required in cout function naveen yadav
@ 2012-01-06  9:46 ` naveen yadav
  2012-01-06  9:46 ` Jonathan Wakely
  1 sibling, 0 replies; 11+ messages in thread
From: naveen yadav @ 2012-01-06  9:46 UTC (permalink / raw)
  To: gcc-help, gcc-help

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 .

Thanks

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Modification required in cout function
  2012-01-06  9:28 Modification required in cout function naveen yadav
  2012-01-06  9:46 ` naveen yadav
@ 2012-01-06  9:46 ` Jonathan Wakely
  2012-01-06  9:48   ` Jonathan Wakely
  1 sibling, 1 reply; 11+ messages in thread
From: Jonathan Wakely @ 2012-01-06  9:46 UTC (permalink / raw)
  To: naveen yadav; +Cc: gcc-help

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?

Changing the standard library probably isn't necessary.

The relevant code is in libstdc++-v3/src/ios_init.cc

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Modification required in cout function
  2012-01-06  9:46 ` Jonathan Wakely
@ 2012-01-06  9:48   ` Jonathan Wakely
  2012-01-06 12:41     ` naveen yadav
  0 siblings, 1 reply; 11+ messages in thread
From: Jonathan Wakely @ 2012-01-06  9:48 UTC (permalink / raw)
  To: naveen yadav; +Cc: gcc-help

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.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Modification required in cout function
  2012-01-06  9:48   ` Jonathan Wakely
@ 2012-01-06 12:41     ` naveen yadav
  2012-01-06 12:41       ` Jonathan Wakely
  2012-01-06 12:55       ` naveen yadav
  0 siblings, 2 replies; 11+ messages in thread
From: naveen yadav @ 2012-01-06 12:41 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-help

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@gmail.com> 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.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Modification required in cout function
  2012-01-06 12:41     ` naveen yadav
@ 2012-01-06 12:41       ` Jonathan Wakely
  2012-01-06 12:55       ` naveen yadav
  1 sibling, 0 replies; 11+ messages in thread
From: Jonathan Wakely @ 2012-01-06 12:41 UTC (permalink / raw)
  To: naveen yadav; +Cc: gcc-help

On 6 January 2012 11:40, naveen yadav 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.

That will probably cause the application to crash when writing to cout.

Why not use one of the simpler alternatives I suggested?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Modification required in cout function
  2012-01-06 12:41     ` naveen yadav
  2012-01-06 12:41       ` Jonathan Wakely
@ 2012-01-06 12:55       ` naveen yadav
  2012-01-06 14:51         ` Jonathan Wakely
  1 sibling, 1 reply; 11+ messages in thread
From: naveen yadav @ 2012-01-06 12:55 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-help

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@gmail.com> 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@gmail.com> 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.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Modification required in cout function
  2012-01-06 12:55       ` naveen yadav
@ 2012-01-06 14:51         ` Jonathan Wakely
  2012-01-07 12:02           ` naveen yadav
  0 siblings, 1 reply; 11+ messages in thread
From: Jonathan Wakely @ 2012-01-06 14:51 UTC (permalink / raw)
  To: naveen yadav; +Cc: gcc-help

On 6 January 2012 12:41, naveen yadav wrote:
> 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().

std::cout.setstate(ios_base::failbit);

If you do that at the top of main() it will prevent any writes to
cout.  If your library writes to cout before main() starts, you could
put that in a global object's constructor (and use
__attribute__((init_priority(101))) to make it run before other global
constructors)

Or if you really insist on modifying the stdlib, do that in
ios_init.cc in ios_base::Init::Init() (not in sync_with_stdio, that's
the wrong place)

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Modification required in cout function
  2012-01-06 14:51         ` Jonathan Wakely
@ 2012-01-07 12:02           ` naveen yadav
  2012-01-07 17:32             ` Jonathan Wakely
  0 siblings, 1 reply; 11+ messages in thread
From: naveen yadav @ 2012-01-07 12:02 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-help

Thanks a lot Jonathan,

The reason for modifying stdlib is needed because i do not have source
code of binary which i want to test.
will you pls let me know execty lines in ios_init.cc  which I need to
modify , this will help me a lot.

Thanks

On Fri, Jan 6, 2012 at 6:25 PM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> On 6 January 2012 12:41, naveen yadav wrote:
>> 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().
>
> std::cout.setstate(ios_base::failbit);
>
> If you do that at the top of main() it will prevent any writes to
> cout.  If your library writes to cout before main() starts, you could
> put that in a global object's constructor (and use
> __attribute__((init_priority(101))) to make it run before other global
> constructors)
>
> Or if you really insist on modifying the stdlib, do that in
> ios_init.cc in ios_base::Init::Init() (not in sync_with_stdio, that's
> the wrong place)

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Modification required in cout function
  2012-01-07 12:02           ` naveen yadav
@ 2012-01-07 17:32             ` Jonathan Wakely
  2012-01-09 12:29               ` naveen yadav
  0 siblings, 1 reply; 11+ messages in thread
From: Jonathan Wakely @ 2012-01-07 17:32 UTC (permalink / raw)
  To: naveen yadav; +Cc: gcc-help

On 7 January 2012 06:49, naveen yadav wrote:
> Thanks a lot Jonathan,
>
> The reason for modifying stdlib is needed because i do not have source
> code of binary which i want to test.
> will you pls let me know execty lines in ios_init.cc  which I need to
> modify , this will help me a lot.

Put
std::cout.setstate(ios_base::failbit);

after cout has been constructed, so around line 102


> Thanks
>
> On Fri, Jan 6, 2012 at 6:25 PM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
>> On 6 January 2012 12:41, naveen yadav wrote:
>>> 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().
>>
>> std::cout.setstate(ios_base::failbit);
>>
>> If you do that at the top of main() it will prevent any writes to
>> cout.  If your library writes to cout before main() starts, you could
>> put that in a global object's constructor (and use
>> __attribute__((init_priority(101))) to make it run before other global
>> constructors)
>>
>> Or if you really insist on modifying the stdlib, do that in
>> ios_init.cc in ios_base::Init::Init() (not in sync_with_stdio, that's
>> the wrong place)

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Modification required in cout function
  2012-01-07 17:32             ` Jonathan Wakely
@ 2012-01-09 12:29               ` naveen yadav
  0 siblings, 0 replies; 11+ messages in thread
From: naveen yadav @ 2012-01-09 12:29 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-help

Thanks a lot Jonathan, it works for me ..


On Sat, Jan 7, 2012 at 5:32 PM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> On 7 January 2012 06:49, naveen yadav wrote:
>> Thanks a lot Jonathan,
>>
>> The reason for modifying stdlib is needed because i do not have source
>> code of binary which i want to test.
>> will you pls let me know execty lines in ios_init.cc  which I need to
>> modify , this will help me a lot.
>
> Put
> std::cout.setstate(ios_base::failbit);
>
> after cout has been constructed, so around line 102
>
>
>> Thanks
>>
>> On Fri, Jan 6, 2012 at 6:25 PM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
>>> On 6 January 2012 12:41, naveen yadav wrote:
>>>> 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().
>>>
>>> std::cout.setstate(ios_base::failbit);
>>>
>>> If you do that at the top of main() it will prevent any writes to
>>> cout.  If your library writes to cout before main() starts, you could
>>> put that in a global object's constructor (and use
>>> __attribute__((init_priority(101))) to make it run before other global
>>> constructors)
>>>
>>> Or if you really insist on modifying the stdlib, do that in
>>> ios_init.cc in ios_base::Init::Init() (not in sync_with_stdio, that's
>>> the wrong place)

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-01-09 11:17 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-06  9:28 Modification required in cout function naveen yadav
2012-01-06  9:46 ` naveen yadav
2012-01-06  9:46 ` Jonathan Wakely
2012-01-06  9:48   ` Jonathan Wakely
2012-01-06 12:41     ` naveen yadav
2012-01-06 12:41       ` Jonathan Wakely
2012-01-06 12:55       ` naveen yadav
2012-01-06 14:51         ` Jonathan Wakely
2012-01-07 12:02           ` naveen yadav
2012-01-07 17:32             ` Jonathan Wakely
2012-01-09 12:29               ` naveen yadav

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).