# Development environment



## balanga (Dec 2, 2017)

Can anyone suggest an Integrated Development Environment for FreeBSD where you can single step through a program, set breakpoints, etc ?

I am aware of https://www.freebsd.org/ports/devel.html but would prefer some recommendations for use with 'C'....


----------



## balanga (Dec 2, 2017)

I tried installing devel/codeblocks but after displaying its logo it just core dumped.

Any suggestions on what to look for?


----------



## balanga (Dec 4, 2017)

It seems as though I need to `pkg install codeblocks-devel`.


----------



## ronaldlees (Dec 25, 2017)

balanga said:


> Can anyone suggest an Integrated Development Environment for FreeBSD where you can single step through a program, set breakpoints, etc ?
> 
> I am aware of https://www.freebsd.org/ports/devel.html but would prefer some recommendations for use with 'C'....



If you do not want to install or you don't need a glitzy GUI styled IDE or Emacs (actually a pretty friendly environment written by Richard Stallman), you can use vim or you can simply use the built-in debugging UI of GDB, by executing gdb with the “-tui” option:




Here it's shown debugging a simple OS kernel from Visopsys.org.  The advantage of using the bare gdb debugger is that it will teach you the basics of debugging, without a fancy front-end GUI that may shield details that could help deeper understanding.  Emacs works via direct interaction with the debugger as well.  Maybe that combo could be a sort of intermediate step to get you going, since it's a very simple command line startup.  Instant gratification, and not much prior knowledge needed.

I kinda like emacs for small projects (grin).  Here's what tha man has to say about it:


----------



## kpedersen (Dec 25, 2017)

(Quite an old post but...)
If you are just starting out with development, then codeblocks is great. However if you are looking at honing your skills professionally, then IDEs are simply too inflexible and the better developers that I have worked with avoid them.

Perhaps try the following instead:

1) clang (C Compiler) or clang++ (C++ compiler)
2) gedit (simple text editor) or vim, emacs (more advanced text editors)
3) gdb, (Debugger so you can set breakpoints, step through the program)

One of the main reasons why IDEs are limited is because they don't well integrate the following important tools:

cmake (cross platform build system. Visual Studio .sln or code::blocks .proj files are not often used by other developers)
valgrind (runtime memory checker)
splint (static analysis)
doxygen (generating callgraphs / reverse callgraphs is very important for large teams)
jenkins / hudson (Build systems work with the command line. They often have very limited support for IDEs)
git / svn (version control support is always lacking in IDEs because the proj files or settings files do not merge well).


----------



## zodias (Jan 16, 2018)

KDevelop is playing nice most of the time.


----------



## fnoyanisi (Jan 31, 2018)

This is one thing I am missing as well....CodeBlock was "okay" but the port has been broken for a while...
I may give a go to editors/codelite, seems like the best bid I (we) have... I have never been a java/eclipse fan to be honest, hence do nto want to go down the Eclipse + CDT track.

The main thing I am looking is a decent integration with gdb.

PS : Lately, I have done some iOS development, hence used Xcode and I think it rocks...


----------



## ShelLuser (Jan 31, 2018)

I'm a big fan of java/netbeans but as its location implies that's mostly because of my Java development. However, Netbeans also supports C/C++ these days and to my understanding also has excellent debugging support (including step traces). Unfortunately I program more with Java than C/C++ so I can't share hands on experience.


----------



## balanga (Jan 31, 2018)

The reason I wanted to set up a development environment where I could single step through code was to find out why kwboot would not work properly on FreeBSD. I download the source and it compiled but just wouldn't work...

See Thread 61777


----------



## aragats (Jan 31, 2018)

balanga said:


> The reason I wanted to set up a development environment where I could single step through code...


An IDE doesn't do any magic. So, the topic looks to be an XY problem.
That program sends data to a serial port, did you check the other end?
Also, you mentioned adding *printf*'s, did you get any result?
(Sorry, these questions should go to another thread you mentioned)


----------



## balanga (Jan 31, 2018)

With an IDE I should be able to set breakpoints and view variables, but programming serial ports is a bit out of my league. I couldn't see any outputs from any *printf*'s but maybe I couldn't figure out where code:blocks shows outputs. Maybe I'll try using gdb...


----------



## unitrunker (Feb 1, 2018)

Code blocks opens a separate window for your stdout.

One IDE not yet mentioned is JuCi++.  It uses CMake as its build system.

Pros: Well integrated with clang. Where Code Blocks would display some obscure STL template header file while single-stepping the debugger (currently it only knows GDB even when compiling with clang/clang++), JuCi shows me the actual source location in my code. Auto-complete in JuCi makes editing a CMakeLists.txt file much easier.

Cons: UI in JuCi is very barren. A few commands (like clean / rebuild-all or closing out a project), are either not there or not obvious. 

Thanks to JuCi, I don't hate on CMake as much as I once did.

> pkg install juci


----------



## Eric A. Borisch (Feb 1, 2018)

lldb has a GUI, too. (Type ‘gui’ while in lldb.)


----------



## kpedersen (Feb 2, 2018)

balanga, You don't need an IDE or a UI to use a debugger.

Make sure you compile your application with debugging symbols '-g'


```
$ clang -g *.c -o debug_program
```

Now if you run your program via gdb (or lldb as mentioned by Eric). Then execute "r" (for run).


```
$ gdb ./debug_program
> r
```

Then when it crashes, you can see the stacktrace by typing "where" and pressing enter.

A very simplistic flow of using gdb but you can also add watchers to variables and put breakpoints on line numbers. Perhaps have a quick read through some gdb tutorials.


----------



## balanga (Feb 2, 2018)

ronaldlees said:


> I kinda like emacs for small projects (grin).




```
root@Test:~/Desktop # pkg install emacs
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
pkg: No packages available to install matching 'emacs' have been found in the repositories
root@Test:~/Desktop #
```
???????


----------



## balanga (Feb 2, 2018)

kpedersen said:


> Then when it crashes, you can see the stacktrace by typing "where" and pressing enter.
> 
> A very simplistic flow of using gdb but you can also add watchers to variables and put breakpoints on line numbers. Perhaps have a quick read through some gdb tutorials.



The program does not crash it just waits and waits... kwboot is  basically a program which send data to a serial port.

This is what it looks like in practice. 

The reason it doesn't work is probably due to the different ways FreeBSD and Linux access serial ports.

BTW how do you use gdb when the program is started with parameters?


----------



## Snurg (Feb 2, 2018)

balanga said:


> BTW how do you use gdb when the program is started with parameters?


at the end of the invoking command line --args <your program args>
You can use the -tui option, this makes gdb a bit easier to use with text ui.
An alternative would be to use a frontend. Personally I think I like kgdb. It uses the same F keys as MS CV. That makes it easy to use if you have experience with CV. There you have a menu item Arguments... Bad is that it has no text command interface, though. So you'll need gdb for more complex things.


----------



## kpedersen (Feb 2, 2018)

As Snurg said the --args parameter (or on the end of the 'r' gdb command such as 'r some/random/path'.

As for debugging programs that do not crash, you can use ctrl-c to interrupt the program where it looks to have frozen. From there you can see the stack trace with "where".

Your output would look something like this.


```
(gdb) r
Starting program: /home/kpedersen/Projects/sandbox/a.out
Hello World
^C
Program received signal SIGINT, Interrupt.
main () at src/main.cpp:12
12        while(true)
(gdb) where
#0  main () at src/main.cpp:12
```


----------



## balanga (Feb 2, 2018)

balanga said:


> ```
> root@Test:~/Desktop #
> Updating FreeBSD repository catalogue...
> FreeBSD repository is up to date.
> ...



`pkg install emacs25`!!!


----------



## jrm@ (Feb 2, 2018)

balanga said:


> ```
> root@Test:~/Desktop # pkg install emacs
> Updating FreeBSD repository catalogue...
> FreeBSD repository is up to date.
> ...





balanga said:


> `pkg install emacs25`!!!



It is a coincidence that you ask this today.  There was an overhaul of the Emacs infrastructure in the ports tree.  There are now flavors and, relevlant to your question, the base package names no longer include the version.  So, when the new packages roll out, it will be `pkg install emacs` (or alternatively one of: `pkg install emacs-nox`, `pkg install emacs-canna`, `pkg install emacs-devel`, `pkg install emacs-devel_nox`).  See the commit log and the UPDATING entry for details.


----------



## Eric A. Borisch (Feb 2, 2018)

Other gdb interfaces: devel/cgdb, devel/ddd, and java/eclipse-cdt, if you’re into that sort of thing.


----------



## Phishfry (Feb 2, 2018)

There is also a plugin for devel/geany and devel/anjuta offering gdb.


----------



## jtotheh (Feb 3, 2018)

Netbeans, though it is made for Java and built with Java, is actually an OK C/C++ IDE for FreeBSD. It's actually the best I've found. I haven't tried Eclipse for this though. QTCreator, though it is good on other OS's, doesn't work well for debugging on FreeBSD.


----------



## fnoyanisi (Feb 3, 2018)

come on, again the topic is bloated with lots of "you do not need a GUI for xxx" kind of answers (very common for answers to questions asking for text editors, IDEs etc.)...OP asks for an IDE, not a debugger CLI. 

I am sorry guys, I have used gdb numerous times, but having a GUI (I am talking about an X-window desktop environment - xfce, kde, gnome, you name it- with windows etc, and I do not consider dozens of tiled terminals as a GUI) and being able to see locals, your watched variables, stack etc. makes life easier....


----------



## drhowarddrfine (Feb 3, 2018)

fnoyanisi You are presuming one is not able to see those things without an IDE and that's not true. You also presume everyone else works like you do and, in our environment, that's definitely not true.


----------



## Snurg (Feb 3, 2018)

drhowarddrfine 
Why I do not like to use pure gdb: http://www.catb.org/esr/writings/unix-koans/oldhand.html


----------



## drhowarddrfine (Feb 3, 2018)

Snurg You are misinterpreting what he's saying. He's not saying don't use Unix tools that have been around a long time.


----------



## Eric A. Borisch (Feb 3, 2018)

fnoyanisi said:


> I am sorry guys, I have used gdb numerous times, but having a GUI (I am talking about an X-window desktop environment - xfce, kde, gnome, you name it- with windows etc, and I do not consider dozens of tiled terminals as a GUI) and being able to see locals, your watched variables, stack etc. makes life easier....



You mean like this: https://camo.githubusercontent.com/...92e696d6775722e636f6d2f486759564d444e2e706e67

I can get code completion, syntax analysis, etc. in vim, and a nice terminal-“gui” debugger in lldb, all in packages that can run on systems that don’t have an X install, like my router box.


----------



## Maelstorm (Feb 3, 2018)

I dunno.  I pretty much just use VI for my coding needs.


----------

