LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-21-2022, 08:17 AM   #1
acal
LQ Newbie
 
Registered: Aug 2011
Posts: 4

Rep: Reputation: Disabled
gdb failing badly with streams reading?


There must be a simple solution to this, but I do not see it. I have this file:

Code:
Is 
this
a bug 
or not
??
and I want to read it with this program:

Code:
#include <fstream>
#include <iostream>

int main() {
  std::string line;
  std::ifstream lund("testStreamInGdb");
  while ( std::getline(lund,line) ) {
    std::cout << line << std::endl;
  }
}
And of course it works:

Code:
omittedPrompt:> g++ -g gdbTest.cc -o gdbTest
omittedPrompt:> gdbTest
Is 
this
a bug 
or not
??
omittedPrompt:>
but NOT in gdb, no sir, not at all:

Code:
omittedPrompt:> gdb gdbTest
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from gdbTest...
(gdb) run
Starting program: omittedDir/gdbTest 
[Inferior 1 (process 10191) exited normally]
(gdb) quit
omittedPrompt:>
It looks like opening the file simply fails.
Could somebody please help and tell me what am I missing? I have a similUbuntu in WSL2, inside Windows 10.

Thank you all for reading this.

Last edited by acal; 06-21-2022 at 08:21 AM.
 
Old 06-21-2022, 08:37 AM   #2
acal
LQ Newbie
 
Registered: Aug 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
Problem is not with GNU but with Windows

I am happy to report that this strange & silly behaviour is only with Windows/WSL2 interaction.
Running the code in gdb inside the trusty Ubuntu Virtualbox is a complete success.
I should have realized it before posting! :-)
 
Old 06-21-2022, 09:03 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120


WSL2 is much closer to what we think of as a vm guest than its predecessor was, but it still ain't a full linux system. In future it would be (very) beneficial to include such data in your initial post. Will save animosity from the wider linux community that expect you to be running a true linux system when trying to help.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
DEBUG WITH GDB ERROR ! - spike: unrecognized option --gdb-port riscv Linux - Newbie 3 03-29-2017 02:59 PM
zypper install gdb, does not install the latest version of GDB Aquarius_Girl SUSE / openSUSE 4 12-30-2010 03:00 AM
normal gdb and spec gdb for kgdb Igor007 Programming 1 09-23-2005 04:15 PM
normal gdb and spec gdb for kgdb Igor007 Linux - Newbie 1 09-23-2005 01:41 PM
gdb .. looking for 32 bit gdb.. for ia64 suse.. nkshirsagar SUSE / openSUSE 0 12-09-2004 03:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration