Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot debug fc::http_server with Visual Studio or CLion #1141

Closed
cogutvalera opened this issue Jul 15, 2018 · 26 comments
Closed

Cannot debug fc::http_server with Visual Studio or CLion #1141

cogutvalera opened this issue Jul 15, 2018 · 26 comments

Comments

@cogutvalera
Copy link
Member

who can help me guys please 😉 ? I cannot debug fc/src/network/http/http_server.cpp even in Visual Studio cannot debug and cannot debug it even in CLion studio, I've placed breakpoints, but nothing helped me and after simple curl http request I cannot see that program pauses inside fc::http_server

at the same time I can debug in Visual Studio and in CLion fc/src/network/http/websocket.cpp, breakpoints work well enough for fc::websocket !

maybe anybody can help me ? maybe should I use another debuggers ? what is your suggestion/advise ? can anybody advise please what is the best app for debugging processes in C++ so I can debug everything in BitShares-Core project even fc::http_server :-) ?

@cogutvalera
Copy link
Member Author

cogutvalera commented Jul 15, 2018

also I need to resolve this issue and only after that I will can resolve #929 issue

@cogutvalera
Copy link
Member Author

Ubuntu 16.04

Visual Studio Code
Version: 1.25.1
Commit: 1dfc5e557209371715f655691b1235b6b26a06be
Date: 2018-07-11T15:40:20.190Z
Electron: 1.7.12
Chrome: 58.0.3029.110
Node.js: 7.9.0
V8: 5.8.283.38
Architecture: x64

I use next launch.json in Visual Studio Code for debugger:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Witness Node (gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/programs/witness_node/witness_node",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

@oxarbitrage
Copy link
Member

i use gdb to debug bitshares, never tried other. don't remember if i debugged those specific files before but gdb should work in all cases.

@cogutvalera
Copy link
Member Author

cogutvalera commented Jul 15, 2018

@oxarbitrage Thx for your answer ! I use gdb too inside Visual Studio Code as you can see in my launch.json configuration file

@cogutvalera
Copy link
Member Author

@oxarbitrage can you try please to debug http_server.cpp code inside fc library ?
websocket.cpp inside fc library I can debug, but cannot debug only http_server.cpp

@oxarbitrage
Copy link
Member

make sure you are debugging the cli_wallet binary and not the witness_node.

@cogutvalera
Copy link
Member Author

why cli_wallet binary and not witness_node binary ? I need to debug fc::http_server because I need to debug how witness_node sends results on http request.

@oxarbitrage can you try please to debug fc::http_server on your side ?

@cogutvalera
Copy link
Member Author

@oxarbitrage I can debug witness_node with fc::websocket
but cannot debug witness_node with fc::http_server

@jmjatlanta
Copy link
Contributor

I use Eclipse CDT with good success on Ubuntu 18.04, and used it for many years on other operating systems and versions, including Ubuntu 16.04.

I am unfamiliar with Visual Studio outside of Windows, so I can't help you much there. But if you want to give Eclpse CDT a try, you may get further.

As for why you cannot debug http_server, give us a hint. Why can't you debug it? Does Visual Studio blow up? Does it say you can't do it? Does it refuse to enter the method? Does it not stop at breakpoints within fc::http_server?

One note: These components are multithreaded. So you may want to set breakpoints to not confuse yourself when the active thread changes.

@cogutvalera
Copy link
Member Author

cogutvalera commented Jul 16, 2018

@jmjatlanta Thank you very much for your answer and help ! 👍

I will try Eclipse CDT immediately now :-) and maybe soon will close this issue !
I cannot debug fc::http_server not only with Visual Studio but also with CLion.
With Visual Studio and CLion I can debug fc::websocket very well !
I know that it is multithreaded, but why fc::websocket can be debugged but fc::http_server not cannot understand. The problem is that my breakpoints not stopped in fc::http_server even with Visual Studio or with CLion like my breakpoints which can be stopped in fc::websocket.

@jmjatlanta
Copy link
Contributor

Common causes of breakpoints not working:

  • The line was never run. This is a common problem that catches even the best developers at times. Step into the function call instead of using breakpoints, and make sure the method you expect to have been called is actually called.
  • library not built with debugging information (probably not the case here, as you can debug other stuff in the same library)
  • code not compiled in ( line 17 is a blank line according to the debugging information, but is an actual line in your new code that has yet to be compiled with debugging information turned on)

@cogutvalera
Copy link
Member Author

cogutvalera commented Jul 16, 2018

@jmjatlanta Thanks a lot 👍 I think 3rd point is the issue because of compilation maybe, don't know now exactly :-) need to check because fc::http_server must be runned by any http requests

I tried to debug all lines of code inside fc::http_server :-)

@oxarbitrage
Copy link
Member

the only place in code that fc::http::server is used is in the cli_wallet

@cogutvalera
Copy link
Member Author

where then in code witness_node sends results on http requests ?

@oxarbitrage
Copy link
Member

it is done with the fc::http::websocket_server

@cogutvalera
Copy link
Member Author

which file inside libraries/fc folder ? cannot understand there are only websocket.cpp and http_server.cpp and http_connection.cpp as I can see

also http_connection.cpp is used by cli_wallet as I can see and http_server.cpp is used by witness_node

@cogutvalera
Copy link
Member Author

does cli_wallet implement http server ? so doesn't witness_node implement http server ?

I think that cli_wallet as I can see in code just use http connection and not http server as you said @oxarbitrage
Also witness_node must implement http server to send results on http requests, isn't it true ?

@oxarbitrage
Copy link
Member

the witness node open an rpc-endpoint to expose the api. this is done with the websocket server. note that to call the api you need to open a websocket connection or by curl. witness node don't have a http interface that you can do myhost.com:8090/api_call/...

@cogutvalera
Copy link
Member Author

cogutvalera commented Jul 16, 2018

@oxarbitrage Thank you very much 👍 I think I was wrong then :-) I will check it now ...

I know that I need to open websocket connection or by curl for API because I need to fix #929 issue.
As described in README in BitShares-Core repo:

$ npm install -g wscat
$ wscat -c ws://127.0.0.1:8090
> {"id":1, "method":"call", "params":[0,"get_accounts",[["1.2.0"]]]}

$ curl --data '{"jsonrpc": "2.0", "method": "call", "params": [0, "get_accounts", [["1.2.0"]]], "id": 1}' http://127.0.0.1:8090/rpc

@abitmore
Copy link
Member

If you want to debug with a specific debugging tool, you need to figure out how to use the tool. To me it's more like basic programming skills. I don't think here is the correct place to discuss it.

@cogutvalera
Copy link
Member Author

@abitmore for you is like basic programming skills ? but why you answered that you don't know what is the problem with debugging ? @ryanRfox told me yesterday that it is better way to discuss it here and not in telegram. @abitmore what is your suggestion where to discuss this ? Because I really can debug all other stuff for example like websocket, but cannot handle responses from RPC-ENDPOINT on cURL requests, is it basic programming skills for you @abitmore then help me please, can you ?

Also I've tried @oxarbitrage solution and can see breakpoints work on wscat requests but not on cURL requests. For example exactly this line of code https://github.com/bitshares/bitshares-fc/blob/0a90eff69778c0ef1d26f75d11d459ca172eff0c/src/network/http/websocket.cpp#L161 can be stopped by breakpoint for wscat requests on sending result, but on cURL requests breakpoints here won't work.

@abitmore
Copy link
Member

but on cURL requests breakpoints here won't work.

As @jmjatlanta mentioned above:

The line was never run. This is a common problem that catches even the best developers at times. Step into the function call instead of using breakpoints, and make sure the method you expect to have been called is actually called.

@cogutvalera
Copy link
Member Author

Also @abitmore I don't want to debug with a specific tool, I just want to debug with any tool but I've tried different debugging tools and cannot debug just some little part in fc library, at the same time other parts of the same fc library I can debug with different debugging tools. @abitmore can you help me please to debug with any debugging tool specific cURL requests for witness_node ? which tool do you suggest for this purpose ? I think if it is really basic programming skills for you than you should help me and after that close this issue :-)

@abitmore
Copy link
Member

For example exactly this line of code https://github.com/bitshares/bitshares-fc/blob/0a90eff69778c0ef1d26f75d11d459ca172eff0c/src/network/http/websocket.cpp#L161 can be stopped by breakpoint for wscat requests on sending result, but on cURL requests breakpoints here won't work.

Please discuss this in issue #929. It's related.

@cogutvalera
Copy link
Member Author

@abitmore ok thx ! I will discuss this issue here #929

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants