├── .github └── FUNDING.yml ├── .gitignore ├── .gitmodules ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── container ├── nginx │ └── gflive.conf └── startup.sh ├── gdb-frontend-plugins └── theme_light │ ├── config.py │ ├── frontend │ ├── css │ │ └── theme_light.css │ ├── html │ │ └── theme_light.html │ └── js │ │ └── theme_light.js │ ├── theme_light.py │ └── urls.py ├── include ├── arg.h ├── instance.h ├── server.h ├── uniqid.h ├── util.h └── websocket.h ├── media ├── btc-donation-qr.png └── gflive-ss.png ├── src ├── arg.c ├── instance.c ├── server.c ├── uniqid.c ├── util.c └── websocket.c └── template └── main.c /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: rohanrhu 2 | patreon: EvrenselKisilik 3 | open_collective: gdbfrontend -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.sublime-project 2 | *.sublime-workspace 3 | *.code-workspace 4 | .vscode 5 | __pycache__ 6 | *.pyc 7 | .swo 8 | .swp 9 | dist 10 | server 11 | 12 | # macOS 13 | 14 | .DS_Store -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "gdb-frontend"] 2 | path = gdb-frontend 3 | url = https://github.com/rohanrhu/gdb-frontend 4 | 5 | [submodule "libjsonic"] 6 | path = lib/jsonic 7 | url = https://github.com/rohanrhu/jsonic 8 | 9 | [submodule "gdb-frontend-plugins/gdb_frontend_live_adapter"] 10 | path = gdb-frontend-plugins/gdb_frontend_live_adapter 11 | url = https://github.com/rohanrhu/gdb-frontend-live-adapter 12 | [submodule "gdb-frontend-live-client"] 13 | path = gdb-frontend-live-client 14 | url = https://github.com/rohanrhu/gdb-frontend-live-client 15 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:buster 2 | 3 | EXPOSE 80 4 | 5 | COPY . /gdb-frontend-live 6 | COPY ./container/nginx/gflive.conf /etc/nginx/sites-available/gflive.conf 7 | 8 | RUN apt update -y && \ 9 | apt upgrade -y && \ 10 | apt install -y gcc \ 11 | build-essential \ 12 | libssl-dev \ 13 | uuid-dev \ 14 | zlib1g-dev \ 15 | make \ 16 | gdb \ 17 | tmux \ 18 | procps \ 19 | python3 \ 20 | nginx 21 | 22 | RUN adduser gflive 23 | 24 | RUN rm /etc/nginx/sites-enabled/default 25 | RUN ln -s /etc/nginx/sites-available/gflive.conf /etc/nginx/sites-enabled/gflive.conf 26 | 27 | WORKDIR /gdb-frontend-live 28 | 29 | RUN make 30 | 31 | CMD ./container/startup.sh -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # GDBFrontendLive is a server that creates sharable GDBFrontend instances and provides online IDEs. 3 | # 4 | # https://github.com/rohanrhu/gdb-frontend-live 5 | # https://oguzhaneroglu.com/projects/gdb-frontend-live/ 6 | # 7 | # Licensed under GNU/GPLv3 8 | # Copyright (C) 2020, Oğuzhan Eroğlu (https://oguzhaneroglu.com/) 9 | # 10 | 11 | CC = gcc 12 | 13 | CFLAGS = -std=c99 \ 14 | -fcommon \ 15 | -I. \ 16 | -g \ 17 | -luuid \ 18 | -lssl \ 19 | -lcrypto \ 20 | -lpthread \ 21 | -lm 22 | 23 | LDFLAGS = 24 | 25 | SOURCES = $(shell find . -wholename "./src/*.c") 26 | HEADERS = $(shell find . -wholename "./include/*.h") 27 | EXECUTABLES = server 28 | OBJECTS = $(addprefix ./dist/, $(notdir $(filter-out ./src/server.o, $(SOURCES:.c=.o)))) 29 | RM = rm -rf 30 | 31 | .PHONY: clean 32 | 33 | all: server 34 | 35 | dist: 36 | mkdir -p dist/ 37 | 38 | server: dist $(OBJECTS) jsonic 39 | $(CC) -o $@ src/server.c $(filter-out dist jsonic, $^) lib/jsonic/jsonic.o $(CFLAGS) $(LDFLAGS) 40 | chmod +x server 41 | $(RM) dist/ 42 | @echo "\033[32mExecutable: ./server is built.\033[0m" 43 | 44 | dist/util.o: 45 | $(CC) -c -o $@ src/util.c $(CFLAGS) $(LDFLAGS) 46 | 47 | dist/instance.o: 48 | $(CC) -c -o $@ src/instance.c $(CFLAGS) $(LDFLAGS) 49 | 50 | dist/uniqid.o: 51 | $(CC) -c -o $@ src/uniqid.c $(CFLAGS) $(LDFLAGS) 52 | 53 | dist/arg.o: 54 | $(CC) -c -o $@ src/arg.c $(CFLAGS) $(LDFLAGS) 55 | 56 | dist/websocket.o: 57 | $(CC) -c -o $@ src/websocket.c $(CFLAGS) $(LDFLAGS) 58 | 59 | jsonic: 60 | make -C lib/jsonic 61 | 62 | clean: 63 | make clean -C lib/jsonic 64 | $(RM) dist/ 65 | $(RM) $(EXECUTABLES) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # `gdb-frontend-live`: online ide/debugger platform based on [gdb-frontend](https://github.com/rohanrhu/gdb-frontend) 🛸👽🌌 2 | 3 | GDBFrontendLive is a server that creates GDBFrontend instances and provides an online sharable IDEs for each individiual users. 4 | 5 | [![GitHub release](https://img.shields.io/github/release/rohanrhu/gdb-frontend.svg?style=flat-square&color=informational)](https://github.com/rohanrhu/gdb-frontend/releases) 6 | [![GitHub issues](https://img.shields.io/github/issues/rohanrhu/gdb-frontend?style=flat-square&color=red)](https://github.com/rohanrhu/gdb-frontend/issues) 7 | [![GitHub forks](https://img.shields.io/github/forks/rohanrhu/gdb-frontend?style=flat-square)](https://github.com/rohanrhu/gdb-frontend/network) 8 | [![GitHub stars](https://img.shields.io/github/stars/rohanrhu/gdb-frontend?style=flat-square)](https://github.com/rohanrhu/gdb-frontend/stargazers) 9 | [![GDBFrontend Discord](https://img.shields.io/discord/780821881783713813.svg?color=7289da&label=Discord&logo=discord&style=flat-square)](https://discord.gg/RyVY9MtB4S) 10 | [![Support me on Patreon](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%3Fusername%3DEvrenselKisilik%26type%3Dpatrons&style=flat-square)](https://patreon.com/EvrenselKisilik) 11 | [![Donate with BTC](https://shields.io/badge/donate-3KBtYfaAT42uVFd6D2XFRDTAoErLz73vpL-yellow?logo=bitcoin&style=flat-square)](#%EF%B8%8F-donate) 12 | 13 | ![gdb-frontend-live](media/gflive-ss.png "GDBFrontendLive is a server that creates GDBFrontend instances and provides an online sharable IDEs for each individiual users.") 14 | 15 | ## Architecture 16 | 17 | ```text 18 | +----------------+ +------------------------+ 19 | | +--------> | 20 | | Client | | GDBFrontendLive | 21 | | (Browser) | | Server | 22 | | <--------+ | 23 | +--^--+----------+ | +-----Instances------+ | 24 | | | | | | | 25 | | | | | +----------------+ | | 26 | | | | | | | | | 27 | | +-----------------------> | | | 28 | | | | | GDBFrontend | | | 29 | +--------------------------+ | | | 30 | | | | | | | 31 | | | +----------------+ | | 32 | | | ... | | 33 | | +--------------------+ | 34 | +------------------------+ 35 | ``` 36 | 37 | ## What is this exactly? 38 | 39 | GFLive provides a platform that creates online shareble IDE/debuggers for each individual user. Once you create an IDE instance, you can share your session and debug together. 40 | 41 | This project may useful for especially educational institutions or teams; they can setup their own GFLive platforms and provide online shareble IDEs. Also, of course it may be useful for individual usages; you can create a lot of debugger instances and use and share them to your friends. 42 | 43 | GDBFrontend is a debugger in fact for now but it provides basic editing features and full access to terminal on a `tmux` session. So you can use even Vim in the terminal or do something else. With debugging features, editing/IDE features will be improved in-time. You can contribute to project, all PRs are welcome. 44 | 45 | **Note:** Still both projects GFlive and GF are very new and on alpha stages. 46 | 47 | ## Use with Docker Containerization 48 | 49 | You can use GFLive with Docker easily. 50 | 51 | Install [Docker](https://www.docker.com/), and follow these simple steps: 52 | 53 | Get the latest GIT revision: 54 | 55 | ```bash 56 | git clone --recursive https://github.com/rohanrhu/gdb-frontend-live.git 57 | cd gdb-frontend-live 58 | ``` 59 | 60 | Run GFLive container easily: 61 | 62 | ```bash 63 | docker build --tag gflive . 64 | docker run --name gflive -p 80:80 gflive 65 | ``` 66 | 67 | Now you can use GFLive on the URL: `http://127.0.0.1/` 68 | 69 | To stop your container you can use Docker Desktop or use command line of Docker: 70 | 71 | ```bash 72 | docker container stop gflive 73 | ``` 74 | 75 | To remove the container and Docker image you can do these: 76 | 77 | ```bash 78 | docker container rm gflive 79 | ``` 80 | 81 | ```bash 82 | docker image rm gflive 83 | ``` 84 | 85 | ### Security with Docker 86 | 87 | If you are using Docker you can ignore full-system access issue for security since everything will work in VMs but if you want to restrict outgoing internet traffic 88 | for GFLive's debugger instances, you still need to restrict internet access; you can do that by using `iptables` for the user that is running Docker if you are using Linux. 89 | 90 | ## Security 91 | 92 | GFLive provides full access on instance user and group that are set by `--instance-user`/`--instance-group`, so the IDE instances can access each other and internet! Also you must be careful for your open ports or DMZ option on your router; if you dont use a router, you must use firewall or setup a complex autharization architecture based on users and ports. 93 | 94 | You can use `iptables` to restrict outgoing internet traffic of GFLive's debugger instances. 95 | 96 | ```bash 97 | sudo iptables -A OUTPUT -m owner --uid-owner $(id -u gflive) -j DROP 98 | ``` 99 | 100 | ## Other Parts 101 | 102 | ### GDBFrontend: [gdb-frontend](https://github.com/rohanrhu/gdb-frontend) 103 | 104 | GDBFrontend to create instances. 105 | 106 | ### Adapter: [gdb-frontend-live-adapter](https://github.com/rohanrhu/gdb-frontend-live-adapter) 107 | 108 | GDBFrontend adapter plugin for adopting instance to GDBFrontendLive. 109 | 110 | ### Client: [gdb-frontend-live-client](https://github.com/rohanrhu/gdb-frontend-live-client) 111 | 112 | Frontend client that connects to GDBFrontendLive server. 113 | 114 | ## Build 115 | 116 | You can build it with GNU Make. 117 | 118 | ```bash 119 | make clean; make 120 | ``` 121 | 122 | ## Requirements 123 | 124 | GFLive does not require anything except [GDBFrontend Requirements](https://github.com/rohanrhu/gdb-frontend#requirements). **You must provide requirements for GDBFrontend.** 125 | 126 | ## Usage 127 | 128 | ```text 129 | # ./server -h 130 | GDBFrontendLive v0.0.1-alpha 131 | Usage: gdbfrontendlive [options] 132 | Options: 133 | --help, -h: Shows this help text. 134 | --version, -v: Shows GDBFrontendLive and GDBFrontend versions. 135 | --host-address=IP, -H IP: Specifies bind address. 136 | --bind-address=IP, -l IP: Specifies host address. (Default is 127.0.0.1) 137 | --ws-port=PORT, -wsp PORT: Specifies GDBFrontend websocket server's port. 138 | --instance-user=USER, -u USER: Sets the user that runs instances. 139 | --instance-group=GROUP, -g GROUP: Sets the group that runs instances. 140 | ``` 141 | 142 | Start server with an instance user: 143 | 144 | ```bash 145 | ./server --instance-user=USERNAME 146 | ``` 147 | 148 | ### Notices 149 | 150 | * You must run the server as root because it sets uids and gids of instance processes. 151 | * CWD must be the directory of server executable. 152 | 153 | ## Client API/Interface 154 | 155 | GFLive provides a WebSocket server to clients. The server uses serialized JSONs for messaging. HTTP server for client is a TODO; you can use [gdb-frontend-live-client](https://github.com/rohanrhu/gdb-frontend-live-client) on `file://` (without a http server) or serve it a simple http server like Apache HTTPD. 156 | 157 | ## Does it support Windows? 158 | 159 | No. You can use it on Linux. 160 | 161 | ### Does it support WSL? 162 | 163 | GDBFrontend supports WSL but GFLive does not. 164 | 165 | ### Issues about WSL 166 | 167 | * GFLive needs random ports and on WSL 1, Random port option is not usable on WSL becasue `/proc/net/tcp` interface is not working on WSL. (WSL 2 does not has this problem.) 168 | 169 | ## Versioning 170 | 171 | Since v0.1.0-git, GFLive switched to a new versioning strategy. 172 | 173 | ### Reading Versions 174 | 175 | In `vX.Y.Z-STABILITY`: 176 | 177 | * `X` is **major** versions, changes long term with major features and enhancements. 178 | * `Y` is **main** versions that include new features and enhancements. 179 | * `Z` is **bugfix** releases of main versions. 180 | * `STABILITY` is stability level of the release. (`alpha`, `beta`, `rcN`, `stable`) 181 | 182 | ## Documentation 183 | 184 | Documentation is TODO yet. 185 | 186 | ## Contributing 187 | 188 | All PRs are welcome. 189 | 190 | ## ❤️ Donate 191 | 192 | ### Patreon 193 | 194 | [![Support me on Patreon](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%3Fusername%3DEvrenselKisilik%26type%3Dpatrons&style=for-the-badge)](https://patreon.com/EvrenselKisilik) 195 | 196 | ### Bitcoin 197 | 198 | You can donate for supporting me :) 199 | 200 | | QR Code | Bitcoin address for donations | 201 | | -------------------------------------------------------------- | -------------------------------------------- | 202 | | ![Bitcoin address QR code for donate](media/btc-donation-qr.png) | **bc1qhvlc762kwuzeawedl9a8z0duhs8449nwwc35e2** | 203 | 204 | Other currencies: 205 | 206 | | Currency | Address | 207 | | -------- | ------------------------------------------ | 208 | | BTC | bc1qhvlc762kwuzeawedl9a8z0duhs8449nwwc35e2 | 209 | | ETH | 0x1D99B2a2D85C34d478dD8519792e82B18f861974 | 210 | | USDT | 0x1D99B2a2D85C34d478dD8519792e82B18f861974 | 211 | | USDC | 0x1D99B2a2D85C34d478dD8519792e82B18f861974 | 212 | | XMR | 88qvS4sfUnLZ7nehFrz3PG1pWovvEgprcUhkmVLaiL8PVAFgfHjspjKPLhWLj3DUcm92rwNQENbJ1ZbvESdukWvh3epBUty | 213 | 214 | ## License 215 | 216 | GNU General Public License v3 (GPL-3) 217 | 218 | You may copy, distribute and modify the software as long as you track changes/dates in source files. Any modifications to or software including (via compiler) GPL-licensed code must also be made available under the GPL along with build & install instructions. 219 | -------------------------------------------------------------------------------- /container/nginx/gflive.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | listen [::]:80; 4 | 5 | root /gdb-frontend-live/gdb-frontend-live-client; 6 | index index.html; 7 | 8 | location / { 9 | try_files $uri $uri/ =404; 10 | } 11 | 12 | location ~ ^/gf/(?\d+)/ { 13 | proxy_http_version 1.1; 14 | proxy_set_header Upgrade $http_upgrade; 15 | proxy_set_header Connection "Upgrade"; 16 | proxy_temp_file_write_size 64k; 17 | proxy_connect_timeout 120s; 18 | proxy_send_timeout 86400; 19 | proxy_read_timeout 86400; 20 | proxy_buffer_size 64k; 21 | proxy_buffers 16 32k; 22 | proxy_busy_buffers_size 64k; 23 | proxy_redirect off; 24 | proxy_request_buffering off; 25 | proxy_buffering off; 26 | rewrite ^/gf/\d+/(.*) /$1 break; 27 | proxy_pass http://127.0.0.1:$port; 28 | } 29 | 30 | location ~ ^/gflive/ws/ { 31 | proxy_http_version 1.1; 32 | proxy_set_header Upgrade $http_upgrade; 33 | proxy_set_header Connection "Upgrade"; 34 | proxy_temp_file_write_size 64k; 35 | proxy_connect_timeout 120s; 36 | proxy_send_timeout 86400; 37 | proxy_read_timeout 86400; 38 | proxy_buffer_size 64k; 39 | proxy_buffers 16 32k; 40 | proxy_busy_buffers_size 64k; 41 | proxy_redirect off; 42 | proxy_request_buffering off; 43 | proxy_buffering off; 44 | rewrite ^/gflive/ws/(.*) /$1 break; 45 | proxy_pass http://127.0.0.1:4551; 46 | } 47 | } -------------------------------------------------------------------------------- /container/startup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | service nginx start 4 | 5 | ./server --instance-user=gflive -l 0.0.0.0 -------------------------------------------------------------------------------- /gdb-frontend-plugins/theme_light/config.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # gdb-frontend is a easy, flexible and extensionable gui debugger 4 | # 5 | # https://github.com/rohanrhu/gdb-frontend 6 | # https://oguzhaneroglu.com/projects/gdb-frontend/ 7 | # 8 | # Licensed under GNU/GPLv3 9 | # Copyright (C) 2019, Oğuzhan Eroğlu (https://oguzhaneroglu.com/) 10 | 11 | DESCRIPTION = "Light theme for GDBFrontend." 12 | AUTHOR = "Oğuzhan Eroğlu (https://oguzhaneroglu.com/)" 13 | HOMEPAGE = "https://github.com/rohanrhu/gdb-frontend" 14 | VERSION = [0, 0, 1] -------------------------------------------------------------------------------- /gdb-frontend-plugins/theme_light/frontend/css/theme_light.css: -------------------------------------------------------------------------------- 1 | /* 2 | * gdb-frontend is a easy, flexible and extensionable gui debugger 3 | * 4 | * https://github.com/rohanrhu/gdb-frontend 5 | * https://oguzhaneroglu.com/projects/gdb-frontend/ 6 | * 7 | * Licensed under GNU/GPLv3 8 | * Copyright (C) 2019, Oğuzhan Eroğlu (https://oguzhaneroglu.com/) 9 | * 10 | */ 11 | 12 | .GDBFrontend { 13 | background: white; 14 | color: black; 15 | } 16 | 17 | .Checkbox_icon_img { 18 | filter: hue-rotate(320deg) contrast(5); 19 | } 20 | 21 | .button1:hover { 22 | background: rgba(0,0,0,0.2); 23 | } 24 | 25 | .GDBFrontend_layout_top { 26 | background: rgba(0, 0, 0, 0.25); 27 | } 28 | 29 | .GDBFrontend_runtimeControls_btn:hover { 30 | background: rgba(0,0,0,0.2); 31 | } 32 | 33 | .GDBFrontend_runtimeControls_btn_img { 34 | filter: invert(1); 35 | } 36 | 37 | .GDBFrontend_load_connectBtn_openable { 38 | background: #999999; 39 | } 40 | 41 | .GDBFrontend_layout_middle_left { 42 | background: rgba(0, 0, 0, 0.25); 43 | } 44 | 45 | .GDBFrontend_sources_title { 46 | background: rgba(0, 0, 0, 0.1); 47 | } 48 | 49 | .GDBFrontend_sources_title_buttons_button_iconImg { 50 | filter: invert(1); 51 | } 52 | 53 | .GDBFrontend_disassembly_title { 54 | background: rgba(0, 0, 0, 0.1); 55 | } 56 | 57 | .GDBFrontend_disassembly_title_buttons_button_iconImg { 58 | filter: invert(1); 59 | } 60 | 61 | .GDBFrontend_watches_title { 62 | background: rgba(0, 0, 0, 0.1); 63 | } 64 | 65 | .GDBFrontend_breakpoints_title { 66 | background: rgba(0, 0, 0, 0.1); 67 | } 68 | 69 | .BreakpointsEditor_items_item_remove { 70 | background: rgba(0, 0, 0, 0.1); 71 | } 72 | 73 | .GDBFrontend_threads_title { 74 | background: rgba(0, 0, 0, 0.1); 75 | } 76 | 77 | .ThreadsEditor_items_item_num { 78 | color: black; 79 | } 80 | 81 | .ThreadsEditor_items_item:nth-child(odd) { 82 | background: rgba(0,0,0,0.05); 83 | } 84 | 85 | .ThreadsEditor_items_item.ThreadsEditor__current { 86 | background: rgb(255, 243, 95, 0.2); 87 | } 88 | 89 | .GDBFrontend_stack_title { 90 | background: rgba(0, 0, 0, 0.1); 91 | } 92 | 93 | .StackTrace_items_item_num { 94 | color: black; 95 | } 96 | 97 | .StackTrace_items_item:nth-child(odd) { 98 | background: rgba(0,0,0,0.05); 99 | } 100 | 101 | .StackTrace_items_item.StackTrace__current { 102 | background: rgb(255, 243, 95, 0.2); 103 | } 104 | 105 | .GDBFrontend_variables_title { 106 | background: rgba(0, 0, 0, 0.1); 107 | } 108 | 109 | .FileTabs_editors_content { 110 | background: rgba(0, 0, 0, 0.3); 111 | } 112 | 113 | .FileTabs_editors_noItem { 114 | background: rgba(0, 0, 0, 0.1); 115 | color: black; 116 | } 117 | 118 | .FileTabs_tabs_items_item_closeBtn { 119 | color: black; 120 | } 121 | 122 | .FileTabs_editors_items_item_variablePopup { 123 | background: #656565; 124 | } 125 | 126 | .GDBFrontend_terminalCloseBtn, 127 | .GDBFrontend_terminalOpenBtn { 128 | background: rgba(255, 255, 255, 0.5); 129 | } 130 | 131 | .SourceTree_items_item__dir .SourceTree_items_item_icon { 132 | color: #fff35f; 133 | } 134 | 135 | .Resizable_resizer_draggable { 136 | background: rgb(0, 0, 0, 0.1); 137 | } 138 | 139 | .Watches_items_item_expression_input_rI { 140 | color: black; 141 | } 142 | 143 | .Watches_items_item_value_input_rI { 144 | color: black; 145 | } 146 | 147 | .Disassembly_items_item_addr { 148 | color: #d9edff; 149 | } 150 | 151 | .VariablesExplorer_items_item_button_type { 152 | color: white; 153 | } 154 | 155 | .VariablesExplorer_items_item_button:nth-child(odd) { 156 | background: rgba(0,0,0,0.075); 157 | } 158 | 159 | .FileTabs_tabs_items_item.FileTabs_tabs_items_item__current { 160 | background: rgb(0, 0, 0, 0.1); 161 | } 162 | 163 | .FileTabs_tabs_items_item_pathTooltip_box { 164 | color: black; 165 | background: #a0a0a0; 166 | } 167 | 168 | .FileTabs_tabs_items_item_pathTooltip_box_arrow:after { 169 | border-bottom: 10px solid #a0a0a0; 170 | } 171 | 172 | .FileBrowser_window_box { 173 | background: #656565; 174 | } 175 | 176 | .EvaluateExpression_window_box { 177 | background: #656565; 178 | color: white; 179 | } 180 | 181 | .EvaluateExpression_window_mover { 182 | background-color: #656565; 183 | } 184 | 185 | .EvaluateExpression_window_box_header_btn.EvaluateExpression__checked { 186 | color: #fff35f; 187 | } 188 | 189 | .GDBFrontend_layout_top_menuBtn:hover .GDBFrontend_layout_top_menuBtn_label { 190 | background: rgba(0, 0, 0, 0.1); 191 | } 192 | 193 | .GDBFrontend_layout_top_menuBtn_openable { 194 | background: #999999; 195 | color: black; 196 | } 197 | 198 | .GDBFrontend_layout_top_menuBtn_openable_items_item, a.GDBFrontend_layout_top_menuBtn_openable_items_item, a.GDBFrontend_layout_top_menuBtn_openable_items_item:visited { 199 | color: black; 200 | } 201 | 202 | .css_AboutDialog_box { 203 | background: #656565; 204 | } 205 | 206 | .FuzzyFinder_box { 207 | background: #656565; 208 | } 209 | 210 | .css_MessageBox_box { 211 | background: #656565; 212 | } -------------------------------------------------------------------------------- /gdb-frontend-plugins/theme_light/frontend/html/theme_light.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohanrhu/gdb-frontend-live/385a39cba9babff9bc257a1260c52a55e78981de/gdb-frontend-plugins/theme_light/frontend/html/theme_light.html -------------------------------------------------------------------------------- /gdb-frontend-plugins/theme_light/frontend/js/theme_light.js: -------------------------------------------------------------------------------- 1 | /* 2 | * gdb-frontend is a easy, flexible and extensionable gui debugger 3 | * 4 | * https://github.com/rohanrhu/gdb-frontend 5 | * https://oguzhaneroglu.com/projects/gdb-frontend/ 6 | * 7 | * Licensed under GNU/GPLv3 8 | * Copyright (C) 2019, Oğuzhan Eroğlu (https://oguzhaneroglu.com/) 9 | * 10 | */ 11 | 12 | $(document).ready(function () { 13 | GDBFrontend.components.gdbFrontend.components.fileTabs.setAceTheme('ace/theme/iplastic'); 14 | }); -------------------------------------------------------------------------------- /gdb-frontend-plugins/theme_light/theme_light.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # gdb-frontend is a easy, flexible and extensionable gui debugger 4 | # 5 | # https://github.com/rohanrhu/gdb-frontend 6 | # https://oguzhaneroglu.com/projects/gdb-frontend/ 7 | # 8 | # Licensed under GNU/GPLv3 9 | # Copyright (C) 2019, Oğuzhan Eroğlu (https://oguzhaneroglu.com/) 10 | 11 | # Example GDBFrontend Plugin 12 | 13 | import importlib 14 | 15 | import plugin 16 | 17 | class ThemeLightPlugin(plugin.GDBFrontendPlugin): 18 | def __init__(self): 19 | plugin.GDBFrontendPlugin.__init__(self) 20 | 21 | def loaded(self): 22 | pass 23 | 24 | def unloaded(self): 25 | pass -------------------------------------------------------------------------------- /gdb-frontend-plugins/theme_light/urls.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # gdb-frontend is a easy, flexible and extensionable gui debugger 4 | # 5 | # https://github.com/rohanrhu/gdb-frontend 6 | # https://oguzhaneroglu.com/projects/gdb-frontend/ 7 | # 8 | # Licensed under GNU/GPLv3 9 | # Copyright (C) 2019, Oğuzhan Eroğlu (https://oguzhaneroglu.com/) 10 | 11 | urls = { 12 | } -------------------------------------------------------------------------------- /include/arg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GDBFrontendLive is a server that creates sharable GDBFrontend instances and provides online IDEs. 3 | * 4 | * https://github.com/rohanrhu/gdb-frontend-live 5 | * https://oguzhaneroglu.com/projects/gdb-frontend-live/ 6 | * 7 | * Licensed under GNU/GPLv3 8 | * Copyright (C) 2020, Oğuzhan Eroğlu (https://oguzhaneroglu.com/) 9 | * 10 | */ 11 | 12 | #ifndef __GDBFRONTENDLIVE_ARG_H__ 13 | #define __GDBFRONTENDLIVE_ARG_H__ 14 | 15 | enum { 16 | GDBFRONTENDLIVE_ARGUMENT_FULL, 17 | GDBFRONTENDLIVE_ARGUMENT_SHORT, 18 | GDBFRONTENDLIVE_ARGUMENT_IS_EXPECT_VALUE, 19 | GDBFRONTENDLIVE_ARGUMENT_FUNCTION 20 | }; 21 | 22 | #define GDBFRONTENDLIVE_ARG_WITH_VALUE (void*) 1 23 | #define GDBFRONTENDLIVE_ARG_WITHOUT_VALUE (void*) 0 24 | 25 | struct gdbfrontendlive_arg { 26 | char** argv; 27 | int argc; 28 | void** arguments; 29 | }; 30 | typedef struct gdbfrontendlive_arg gdbfrontendlive_arg_t; 31 | 32 | typedef void (*gdbfrontendlive_arg_function_t)(char*); 33 | 34 | extern gdbfrontendlive_arg_t* gdbfrontendlive_arg_init(char** argv, int argc, void** arguments); 35 | extern void gdbfrontendlive_arg_handle(gdbfrontendlive_arg_t* arg); 36 | 37 | #endif -------------------------------------------------------------------------------- /include/instance.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GDBFrontendLive is a server that creates sharable GDBFrontend instances and provides online IDEs. 3 | * 4 | * https://github.com/rohanrhu/gdb-frontend-live 5 | * https://oguzhaneroglu.com/projects/gdb-frontend-live/ 6 | * 7 | * Licensed under GNU/GPLv3 8 | * Copyright (C) 2020, Oğuzhan Eroğlu (https://oguzhaneroglu.com/) 9 | * 10 | */ 11 | 12 | #ifndef __GDBFRONTENDLIVE_INSTANCE_H__ 13 | #define __GDBFRONTENDLIVE_INSTANCE_H__ 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include "../include/util.h" 20 | #include "../include/websocket.h" 21 | 22 | extern char* gdbfrontendlive_instance_user_name; 23 | extern uid_t gdbfrontendlive_instance_user_uid; 24 | 25 | extern char* gdbfrontendlive_instance_group_name; 26 | extern uid_t gdbfrontendlive_instance_group_gid; 27 | 28 | typedef struct gdbfrontendlive_instance_gfproc gdbfrontendlive_instance_gfproc_t; 29 | struct gdbfrontendlive_instance_gfproc { 30 | pid_t pid; 31 | }; 32 | 33 | typedef struct gdbfrontendlive_websocket_clients gdbfrontendlive_websocket_clients_t; 34 | 35 | typedef struct gdbfrontendlive_instance gdbfrontendlive_instance_t; 36 | struct gdbfrontendlive_instance { 37 | char* id; 38 | char* workdir; 39 | int is_running; 40 | char* host_address; 41 | char* bind_address; 42 | gdbfrontendlive_instance_gfproc_t* gfproc; 43 | u_int16_t http_port; 44 | gdbfrontendlive_websocket_clients_t* client; 45 | gdbfrontendlive_instance_t* prev; 46 | gdbfrontendlive_instance_t* next; 47 | }; 48 | 49 | gdbfrontendlive_instance_t* instances; 50 | gdbfrontendlive_instance_t* instances_current; 51 | 52 | extern gdbfrontendlive_instance_t* gdbfrontendlive_instance_create(); 53 | extern void gdbfrontendlive_instance_run(gdbfrontendlive_instance_t* instance); 54 | extern void gdbfrontendlive_instance_destroy(gdbfrontendlive_instance_t* instance); 55 | extern gdbfrontendlive_instance_t* gdbfrontendlive_instance_getby_id(char* id); 56 | 57 | static void proc_exit_handler(int status); 58 | 59 | #endif -------------------------------------------------------------------------------- /include/server.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GDBFrontendLive is a server that creates sharable GDBFrontend instances and provides online IDEs. 3 | * 4 | * https://github.com/rohanrhu/gdb-frontend-live 5 | * https://oguzhaneroglu.com/projects/gdb-frontend-live/ 6 | * 7 | * Licensed under GNU/GPLv3 8 | * Copyright (C) 2020, Oğuzhan Eroğlu (https://oguzhaneroglu.com/) 9 | * 10 | */ 11 | 12 | #ifndef __GDBFRONTENDLIVE_SERVER_H__ 13 | #define __GDBFRONTENDLIVE_SERVER_H__ 14 | 15 | #include "../include/util.h" 16 | #include "../include/instance.h" 17 | #include "../include/arg.h" 18 | 19 | #define GDBFRONTENDLIVE_DEFAULT_WS_PORT 4551 20 | 21 | #define GDBFRONTENDLIVE_VERSION {0, 2, 1, "beta", '\0'} 22 | #define GDBFRONTENDLIVE_VERSION_STRING "v0.2.1-beta" 23 | 24 | #define GDBFRONTENDLIVE_GF_VERSION {0, 11, 4, "git", '\0'} 25 | #define GDBFRONTENDLIVE_GF_VERSION_STRING "v0.11.4-git" 26 | 27 | char* gdbfrontendlive_host; 28 | char* gdbfrontendlive_bind; 29 | 30 | static void arg_handler_help(char* value); 31 | static void arg_handler_version(char* value); 32 | static void arg_handler_ws_port(char* value); 33 | static void arg_handler_instance_user(char* username); 34 | static void arg_handler_instance_group(char* groupname); 35 | static void arg_handler_host_address(char* addr); 36 | static void arg_handler_bind_address(char* addr); 37 | 38 | static void* arguments[] = { 39 | "--help", "-h", GDBFRONTENDLIVE_ARG_WITHOUT_VALUE, arg_handler_help, 40 | "--version", "-v", GDBFRONTENDLIVE_ARG_WITHOUT_VALUE, arg_handler_version, 41 | "--host-address", "-H", GDBFRONTENDLIVE_ARG_WITH_VALUE, arg_handler_host_address, 42 | "--bind-address", "-l", GDBFRONTENDLIVE_ARG_WITH_VALUE, arg_handler_bind_address, 43 | "--ws-port", "-wsp", GDBFRONTENDLIVE_ARG_WITH_VALUE, arg_handler_ws_port, 44 | "--instance-user", "-u", GDBFRONTENDLIVE_ARG_WITH_VALUE, arg_handler_instance_user, 45 | "--instance-group", "-g", GDBFRONTENDLIVE_ARG_WITH_VALUE, arg_handler_instance_group, 46 | NULL 47 | }; 48 | 49 | #endif -------------------------------------------------------------------------------- /include/uniqid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GDBFrontendLive is a server that creates sharable GDBFrontend instances and provides online IDEs. 3 | * 4 | * https://github.com/rohanrhu/gdb-frontend-live 5 | * https://oguzhaneroglu.com/projects/gdb-frontend-live/ 6 | * 7 | * Licensed under GNU/GPLv3 8 | * Copyright (C) 2020, Oğuzhan Eroğlu (https://oguzhaneroglu.com/) 9 | * 10 | */ 11 | 12 | #ifndef __GDBFRONTENDLIVE_UNIQID_H__ 13 | #define __GDBFRONTENDLIVE_UNIQID_H__ 14 | 15 | extern char* gdbfrontendlive_uniqid(); 16 | 17 | #endif -------------------------------------------------------------------------------- /include/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GDBFrontendLive is a server that creates sharable GDBFrontend instances and provides online IDEs. 3 | * 4 | * https://github.com/rohanrhu/gdb-frontend-live 5 | * https://oguzhaneroglu.com/projects/gdb-frontend-live/ 6 | * 7 | * Licensed under GNU/GPLv3 8 | * Copyright (C) 2020, Oğuzhan Eroğlu (https://oguzhaneroglu.com/) 9 | * 10 | */ 11 | 12 | #ifndef __GDBFRONTENDLIVE_UTIL_H__ 13 | #define __GDBFRONTENDLIVE_UTIL_H__ 14 | 15 | extern void gdbfrontendlive_verbose(char* text, ...); 16 | extern void gdbfrontendlive_set_verbose(int _is_verbose); 17 | 18 | extern char* gdbfrontendlive_util_base64_encode(char* str); 19 | extern char* gdbfrontendlive_util_base64_decode(char* str); 20 | 21 | #endif -------------------------------------------------------------------------------- /include/websocket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GDBFrontendLive is a server that creates sharable GDBFrontend instances and provides online IDEs. 3 | * 4 | * https://github.com/rohanrhu/gdb-frontend-live 5 | * https://oguzhaneroglu.com/projects/gdb-frontend-live/ 6 | * 7 | * Licensed under GNU/GPLv3 8 | * Copyright (C) 2020, Oğuzhan Eroğlu (https://oguzhaneroglu.com/) 9 | * 10 | */ 11 | 12 | #ifndef __GDBFRONTENDLIVE_WEBSOCKET_H__ 13 | #define __GDBFRONTENDLIVE_WEBSOCKET_H__ 14 | 15 | #include 16 | 17 | #include "../include/util.h" 18 | #include "../include/instance.h" 19 | 20 | #define gdbfrontendlive_websocket_packet_frame_header \ 21 | uint8_t fin_rsv_opcode; \ 22 | uint8_t mlen8; 23 | ; 24 | 25 | typedef struct gdbfrontendlive_websocket_packet_frame_len8 gdbfrontendlive_websocket_packet_frame_len8_t; 26 | struct gdbfrontendlive_websocket_packet_frame_len8 { 27 | gdbfrontendlive_websocket_packet_frame_header 28 | }; 29 | 30 | typedef struct gdbfrontendlive_websocket_packet_frame_len16 gdbfrontendlive_websocket_packet_frame_len16_t; 31 | struct gdbfrontendlive_websocket_packet_frame_len16 { 32 | gdbfrontendlive_websocket_packet_frame_header 33 | uint16_t len16; 34 | }; 35 | 36 | typedef struct gdbfrontendlive_websocket_packet_frame_len64 gdbfrontendlive_websocket_packet_frame_len64_t; 37 | struct gdbfrontendlive_websocket_packet_frame_len64 { 38 | gdbfrontendlive_websocket_packet_frame_header 39 | uint64_t len64; 40 | }; 41 | 42 | #define GDBFRONTENDLIVE_WEBSOCKET_GUID "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" 43 | 44 | #define HTTP_HEADER_BUFF_SIZE 700 45 | #define HTTP_PROP_BUFF_SIZE 40 46 | #define HTTP_VAL_BUFF_SIZE 50 47 | 48 | enum GDBFRONTEND_WEBSOCKET_HTTP_HEADER_PARSER_STATE { 49 | GDBFRONTEND_WEBSOCKET_HTTP_HEADER_PARSER_STATE_METHOD = 1, 50 | GDBFRONTEND_WEBSOCKET_HTTP_HEADER_PARSER_STATE_PROP, 51 | GDBFRONTEND_WEBSOCKET_HTTP_HEADER_PARSER_STATE_SPACE, 52 | GDBFRONTEND_WEBSOCKET_HTTP_HEADER_PARSER_STATE_VAL, 53 | GDBFRONTEND_WEBSOCKET_HTTP_HEADER_PARSER_STATE_CR, 54 | GDBFRONTEND_WEBSOCKET_HTTP_HEADER_PARSER_STATE_END 55 | }; 56 | 57 | enum GDBFRONTEND_WEBSOCKET_RESPONSE { 58 | GDBFRONTEND_WEBSOCKET_RESPONSE_INSTANCE_PORT = 1 59 | }; 60 | 61 | typedef struct gdbfrontendlive_websocket gdbfrontendlive_websocket_t; 62 | typedef struct gdbfrontendlive_websocket_clients gdbfrontendlive_websocket_clients_t; 63 | 64 | struct gdbfrontendlive_websocket { 65 | int port; 66 | char* host_address; 67 | char* bind_address; 68 | gdbfrontendlive_websocket_clients_t* clients; 69 | }; 70 | 71 | typedef struct gdbfrontendlive_instance gdbfrontendlive_instance_t; 72 | 73 | struct gdbfrontendlive_websocket_clients { 74 | gdbfrontendlive_websocket_t* ws; 75 | int socket; 76 | int server_socket; 77 | int address; 78 | char* ws_key; 79 | int is_host; 80 | gdbfrontendlive_instance_t* instance; 81 | gdbfrontendlive_websocket_clients_t* prev; 82 | gdbfrontendlive_websocket_clients_t* next; 83 | }; 84 | 85 | gdbfrontendlive_websocket_t* gdbfrontendlive_websocket_init(int port); 86 | void gdbfrontendlive_websocket_listen(gdbfrontendlive_websocket_t* ws); 87 | void gdbfrontendlive_websocket_free(gdbfrontendlive_websocket_t* ws); 88 | 89 | extern gdbfrontendlive_websocket_clients_t* gdbfrontendlive_websocket_client_init(); 90 | extern void gdbfrontendlive_websocket_client_free(gdbfrontendlive_websocket_clients_t* client); 91 | 92 | static void client_handler(gdbfrontendlive_websocket_clients_t* client); 93 | static void receive_http_packet(gdbfrontendlive_websocket_clients_t* client); 94 | static void receive_ws_packet(gdbfrontendlive_websocket_clients_t* client); 95 | static void send_ws_packet(gdbfrontendlive_websocket_clients_t* client, char* message); 96 | static void client_disconnected(gdbfrontendlive_websocket_clients_t* client); 97 | 98 | void broken_pipe_handler(int sig); 99 | 100 | #endif -------------------------------------------------------------------------------- /media/btc-donation-qr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohanrhu/gdb-frontend-live/385a39cba9babff9bc257a1260c52a55e78981de/media/btc-donation-qr.png -------------------------------------------------------------------------------- /media/gflive-ss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohanrhu/gdb-frontend-live/385a39cba9babff9bc257a1260c52a55e78981de/media/gflive-ss.png -------------------------------------------------------------------------------- /src/arg.c: -------------------------------------------------------------------------------- 1 | /* 2 | * GDBFrontendLive is a server that creates sharable GDBFrontend instances and provides online IDEs. 3 | * 4 | * https://github.com/rohanrhu/gdb-frontend-live 5 | * https://oguzhaneroglu.com/projects/gdb-frontend-live/ 6 | * 7 | * Licensed under GNU/GPLv3 8 | * Copyright (C) 2020, Oğuzhan Eroğlu (https://oguzhaneroglu.com/) 9 | * 10 | */ 11 | 12 | #define _GNU_SOURCE 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include "../include/arg.h" 20 | 21 | #include "../include/util.h" 22 | 23 | extern gdbfrontendlive_arg_t* gdbfrontendlive_arg_init(char** argv, int argc, void** arguments) { 24 | gdbfrontendlive_arg_t* arg = malloc(sizeof(gdbfrontendlive_arg_t)); 25 | 26 | arg->argv = argv; 27 | arg->argc = argc; 28 | arg->arguments = arguments; 29 | 30 | return arg; 31 | } 32 | 33 | extern void gdbfrontendlive_arg_handle(gdbfrontendlive_arg_t* arg) { 34 | char* _taken; 35 | int _taken_i; 36 | 37 | gdbfrontendlive_arg_function_t expector_f = NULL; 38 | char* expector_s = NULL; 39 | 40 | int _argument_i; 41 | char* _full; 42 | char* _short; 43 | void* _is_expect_value; 44 | gdbfrontendlive_arg_function_t _function; 45 | 46 | int is_found; 47 | 48 | for (_taken_i=1; _taken_i < arg->argc; _taken_i++) { 49 | _taken = arg->argv[_taken_i]; 50 | 51 | if (expector_f) { 52 | expector_f(_taken); 53 | expector_f = NULL; 54 | expector_s = NULL; 55 | continue; 56 | } 57 | 58 | is_found = 0; 59 | 60 | for (_argument_i=0;; _argument_i++) { 61 | _full = arg->arguments[_argument_i*4 + GDBFRONTENDLIVE_ARGUMENT_FULL]; 62 | if (_full == NULL) break; 63 | _short = arg->arguments[_argument_i*4 + GDBFRONTENDLIVE_ARGUMENT_SHORT]; 64 | _is_expect_value = arg->arguments[_argument_i*4 + GDBFRONTENDLIVE_ARGUMENT_IS_EXPECT_VALUE]; 65 | _function = arg->arguments[_argument_i*4 + GDBFRONTENDLIVE_ARGUMENT_FUNCTION]; 66 | 67 | if (strcmp(_taken, _short) == 0) { 68 | if (_is_expect_value == NULL) _function(NULL); 69 | else { 70 | expector_f = _function; 71 | expector_s = _short; 72 | } 73 | 74 | break; 75 | } 76 | 77 | if ((_is_expect_value == NULL) && (strcmp(_taken, _full) == 0)) { 78 | _function(NULL); 79 | continue; 80 | } 81 | 82 | if (_is_expect_value == NULL) { 83 | continue; 84 | } 85 | 86 | if (strncmp(_taken, _full, strlen(_full)) != 0) { 87 | continue; 88 | } 89 | 90 | int _taken_len = strlen(_taken); 91 | int _full_len = strlen(_full); 92 | 93 | if ((_taken[_full_len] != '=') || (_taken[_full_len+1] == '\0')) { 94 | continue; 95 | } 96 | 97 | _function(_taken+_full_len+1); 98 | 99 | is_found = 1; 100 | } 101 | 102 | if (!is_found && !expector_f) { 103 | printf("Invalid option: %s\n", _taken); 104 | exit(0); 105 | } 106 | } 107 | 108 | if (expector_f) { 109 | printf("Missing value for: %s\n", expector_s); 110 | exit(0); 111 | } 112 | } -------------------------------------------------------------------------------- /src/instance.c: -------------------------------------------------------------------------------- 1 | /* 2 | * GDBFrontendLive is a server that creates sharable GDBFrontend instances and provides online IDEs. 3 | * 4 | * https://github.com/rohanrhu/gdb-frontend-live 5 | * https://oguzhaneroglu.com/projects/gdb-frontend-live/ 6 | * 7 | * Licensed under GNU/GPLv3 8 | * Copyright (C) 2020, Oğuzhan Eroğlu (https://oguzhaneroglu.com/) 9 | * 10 | */ 11 | 12 | #define _GNU_SOURCE 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "../include/instance.h" 29 | 30 | #include "../include/util.h" 31 | #include "../include/uniqid.h" 32 | 33 | char* gdbfrontendlive_instance_user_name = NULL; 34 | uid_t gdbfrontendlive_instance_user_uid = 0; 35 | 36 | char* gdbfrontendlive_instance_group_name = NULL; 37 | gid_t gdbfrontendlive_instance_group_gid = 0; 38 | 39 | gdbfrontendlive_instance_t* instances = NULL; 40 | gdbfrontendlive_instance_t* instances_current = NULL; 41 | 42 | static void sigabrt_handler() { 43 | printf("SIGABRT received."); 44 | } 45 | 46 | extern gdbfrontendlive_instance_t* gdbfrontendlive_instance_create() { 47 | gdbfrontendlive_instance_t* instance = malloc(sizeof(gdbfrontendlive_instance_t)); 48 | instance->is_running = 0; 49 | instance->id = gdbfrontendlive_uniqid(); 50 | instance->client = NULL; 51 | instance->workdir = NULL; 52 | instance->host_address = NULL; 53 | instance->bind_address = NULL; 54 | 55 | gdbfrontendlive_verbose("Instance created #%s\n", instance->id); 56 | 57 | return instance; 58 | } 59 | 60 | extern void gdbfrontendlive_instance_run(gdbfrontendlive_instance_t* instance) { 61 | signal(SIGCHLD, proc_exit_handler); 62 | 63 | char plugins_dir[200]; 64 | realpath("gdb-frontend-plugins", plugins_dir); 65 | 66 | char workdir_base[100]; 67 | char workdir[200]; 68 | 69 | if (gdbfrontendlive_instance_user_uid) { 70 | sprintf(workdir_base, "/home/%s/gflive_instances", gdbfrontendlive_instance_user_name); 71 | } else { 72 | sprintf(workdir_base, "/root/gflive_instances"); 73 | } 74 | 75 | sprintf(workdir, "%s/%s", workdir_base, instance->id); 76 | 77 | DIR* base = opendir(workdir_base); 78 | if (base) { 79 | closedir(base); 80 | } else if (errno == ENOENT) { 81 | mkdir(workdir_base, S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP | S_IXUSR); 82 | chown(workdir_base, gdbfrontendlive_instance_user_uid, gdbfrontendlive_instance_group_gid); 83 | } 84 | 85 | mkdir(workdir, S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP | S_IXUSR); 86 | chown(workdir, gdbfrontendlive_instance_user_uid, gdbfrontendlive_instance_group_gid); 87 | 88 | instance->workdir = malloc(strlen(workdir)+1); 89 | strcpy(instance->workdir, workdir); 90 | 91 | char mf[50]; 92 | sprintf(mf, "%s/main.c", instance->workdir); 93 | 94 | char cp_templ[300]; 95 | sprintf(cp_templ, "cp template/main.c %s", mf); 96 | 97 | system(cp_templ); 98 | chown(mf, gdbfrontendlive_instance_user_uid, gdbfrontendlive_instance_group_gid); 99 | chmod(mf, S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP); 100 | 101 | instance->gfproc = malloc(sizeof(gdbfrontendlive_instance_gfproc_t)); 102 | instance->gfproc->pid = 0; 103 | 104 | uid_t euid, ruid; 105 | 106 | char gf_executable[PATH_MAX+1]; 107 | realpath("gdb-frontend/gdbfrontend", gf_executable); 108 | 109 | char* tmp = "/tmp/gdbfrontend-mmap-"; 110 | int tmp_len = sizeof("/tmp/gdbfrontend-mmap-")-1; 111 | int id_len = strlen(instance->id); 112 | int len = tmp_len+id_len; 113 | char* mmap_path = malloc(len+1); 114 | mmap_path[len] = '\0'; 115 | memcpy(mmap_path, tmp, tmp_len); 116 | memcpy(mmap_path+tmp_len, instance->id, id_len); 117 | 118 | int pagesize = getpagesize(); 119 | 120 | int fd = open(mmap_path, O_CREAT | O_TRUNC | O_RDWR); 121 | chown(mmap_path, gdbfrontendlive_instance_user_uid, gdbfrontendlive_instance_group_gid); 122 | chmod(mmap_path, S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP); 123 | 124 | for (int i=0; i < pagesize; i++) { 125 | lseek(fd, i, SEEK_CUR); 126 | write(fd, "\0", 1); 127 | } 128 | 129 | void* map = mmap(NULL, pagesize, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_FILE | MAP_SHARED, fd, 0); 130 | if (map == MAP_FAILED) { 131 | perror("mmap() error.\n"); 132 | } 133 | 134 | instance->prev = NULL; 135 | instance->next = NULL; 136 | 137 | if (!instances) { 138 | instances = instance; 139 | } else { 140 | instance->prev = instances_current; 141 | instances_current->next = instance; 142 | } 143 | 144 | instances_current = instance; 145 | 146 | pid_t ppid = getpid(); 147 | instance->gfproc->pid = fork(); 148 | 149 | if (instance->gfproc->pid == 0) { 150 | sigaction(SIGABRT, &(struct sigaction){sigabrt_handler}, NULL); 151 | 152 | if (instance->client) { 153 | close(instance->client->socket); 154 | close(instance->client->server_socket); 155 | } 156 | 157 | gdbfrontendlive_verbose("Instance[%s] Running GDBFrontend..\n", instance->id); 158 | 159 | setpgid(0, getpid()); 160 | 161 | gid_t groups[] = {gdbfrontendlive_instance_group_gid}; 162 | setgroups(sizeof(groups), groups); 163 | 164 | setgid(gdbfrontendlive_instance_group_gid); 165 | setuid(gdbfrontendlive_instance_user_uid); 166 | 167 | gdbfrontendlive_verbose("Running exectuable: %s\n", gf_executable); 168 | 169 | char* args[] = { 170 | gf_executable, 171 | "-l", (!instance->bind_address) ? "0.0.0.0": instance->bind_address, 172 | "-H", (!instance->host_address) ? "127.0.0.1": instance->host_address, 173 | "-p", "0", 174 | "-t", instance->id, 175 | "-w", instance->workdir, 176 | "-P", plugins_dir, 177 | "-D", 178 | "-u", "./", 179 | NULL 180 | }; 181 | 182 | execvp(gf_executable, args); 183 | 184 | printf("exec() error: %s\n", strerror(errno)); 185 | exit(1); 186 | } 187 | 188 | gdbfrontendlive_verbose("GDBFrontend is spawned as PID: %d\n", instance->gfproc->pid); 189 | 190 | u_int16_t port = 0; 191 | 192 | while (!port) { 193 | port = ((int*)map)[0]; 194 | } 195 | 196 | instance->http_port = port; 197 | 198 | gdbfrontendlive_verbose("HTTP Port (%u) is using by instance (%s)\n", instance->http_port, instance->id); 199 | 200 | munmap(map, pagesize); 201 | close(fd); 202 | 203 | instance->is_running = 1; 204 | } 205 | 206 | extern void gdbfrontendlive_instance_destroy(gdbfrontendlive_instance_t* instance) { 207 | gdbfrontendlive_verbose("Removing instance #%s\n", instance->id); 208 | 209 | if (instance->is_running && instance->gfproc->pid) { 210 | killpg(getpgid(instance->gfproc->pid), SIGKILL); 211 | kill(instance->gfproc->pid, SIGKILL); 212 | } 213 | 214 | pid_t pid = fork(); 215 | 216 | if (pid == 0) { 217 | gid_t groups[] = {gdbfrontendlive_instance_group_gid}; 218 | setgroups(sizeof(groups), groups); 219 | 220 | setgid(gdbfrontendlive_instance_group_gid); 221 | setuid(gdbfrontendlive_instance_user_uid); 222 | 223 | char command[300]; 224 | sprintf(command, "tmux kill-session -t %s", instance->id); 225 | system(command); 226 | 227 | exit(0); 228 | } 229 | 230 | waitpid(pid, NULL, 0); 231 | 232 | if (instances == instance) { 233 | instances = NULL; 234 | } 235 | 236 | if (instance->prev) { 237 | instance->prev->next = instance->next; 238 | } 239 | 240 | if (instance->next) { 241 | instance->next->prev = instance->prev; 242 | } 243 | 244 | if (instance->workdir) { 245 | char rmrf[200]; 246 | sprintf(rmrf, "rm -rf %s", instance->workdir); 247 | 248 | system(rmrf); 249 | 250 | if (instance->workdir) { 251 | free(instance->workdir); 252 | instance->workdir = NULL; 253 | } 254 | } 255 | 256 | if (instance->gfproc) { 257 | free(instance->gfproc); 258 | instance->gfproc = NULL; 259 | } 260 | 261 | free(instance); 262 | } 263 | 264 | extern gdbfrontendlive_instance_t* gdbfrontendlive_instance_getby_id(char* id) { 265 | gdbfrontendlive_instance_t* instance = instances; 266 | 267 | if (!instance) { 268 | return NULL; 269 | } 270 | 271 | loop: 272 | 273 | if (strcmp(instance->id, id) == 0) { 274 | return instance; 275 | } 276 | 277 | if (instance->next) { 278 | instance = instance->next; 279 | goto loop; 280 | } 281 | 282 | return NULL; 283 | } 284 | 285 | static void proc_exit_handler(int status) { 286 | while (waitpid(-1, NULL, WNOHANG) > 0); 287 | } -------------------------------------------------------------------------------- /src/server.c: -------------------------------------------------------------------------------- 1 | /* 2 | * GDBFrontendLive is a server that creates sharable GDBFrontend instances and provides online IDEs. 3 | * 4 | * https://github.com/rohanrhu/gdb-frontend-live 5 | * https://oguzhaneroglu.com/projects/gdb-frontend-live/ 6 | * 7 | * Licensed under GNU/GPLv3 8 | * Copyright (C) 2020, Oğuzhan Eroğlu (https://oguzhaneroglu.com/) 9 | * 10 | */ 11 | 12 | #define _GNU_SOURCE 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include "../include/server.h" 20 | 21 | #include "../include/util.h" 22 | #include "../include/arg.h" 23 | #include "../include/instance.h" 24 | #include "../include/websocket.h" 25 | 26 | char* gdbfrontendlive_host = NULL; 27 | char* gdbfrontendlive_bind = NULL; 28 | 29 | int gdbfrontendlive_ws_port = GDBFRONTENDLIVE_DEFAULT_WS_PORT; 30 | 31 | static void sigabrt_handler() { 32 | printf("SIGABRT received."); 33 | } 34 | 35 | int main(int argc, char** argv) { 36 | printf("GDBFrontendLive %s\n", GDBFRONTENDLIVE_VERSION_STRING); 37 | 38 | sigaction(SIGABRT, &(struct sigaction){sigabrt_handler}, NULL); 39 | 40 | gdbfrontendlive_instance_user_uid = 0; 41 | gdbfrontendlive_instance_group_gid = 0; 42 | 43 | gdbfrontendlive_arg_t* arg; 44 | arg = gdbfrontendlive_arg_init(argv, argc, (void**)arguments); 45 | gdbfrontendlive_arg_handle(arg); 46 | 47 | if (!gdbfrontendlive_instance_user_uid) { 48 | printf("\033[31m[Error] You must specify instance user. (Example: --instance-user=USERNAME)\033[0m\n"); 49 | exit(1); 50 | } 51 | 52 | if (!gdbfrontendlive_instance_group_gid) { 53 | gdbfrontendlive_instance_group_gid = gdbfrontendlive_instance_user_uid; 54 | } 55 | 56 | if (!gdbfrontendlive_host) { 57 | gdbfrontendlive_host = malloc(10); 58 | sprintf(gdbfrontendlive_host, "127.0.0.1"); 59 | } 60 | 61 | if (!gdbfrontendlive_bind) { 62 | gdbfrontendlive_bind = malloc(8); 63 | sprintf(gdbfrontendlive_host, "0.0.0.0"); 64 | } 65 | 66 | gdbfrontendlive_websocket_t* ws; 67 | ws = gdbfrontendlive_websocket_init(gdbfrontendlive_ws_port); 68 | ws->host_address = gdbfrontendlive_host; 69 | ws->bind_address = gdbfrontendlive_bind; 70 | 71 | gdbfrontendlive_websocket_listen(ws); 72 | 73 | return 0; 74 | } 75 | 76 | static void arg_handler_help(char* value) { 77 | printf("Usage: gdbfrontendlive [options]\n"); 78 | printf("Options:\n"); 79 | printf("\t--help, -h:\t\t\t\tShows this help text.\n"); 80 | printf("\t--version, -v:\t\t\t\tShows GDBFrontendLive and GDBFrontend versions.\n"); 81 | printf("\t--host-address=IP, -H IP:\t\tSpecifies bind address.\n"); 82 | printf("\t--bind-address=IP, -l IP:\t\tSpecifies host address. (Default is 127.0.0.1)\n"); 83 | printf("\t--ws-port=PORT, -wsp PORT:\t\tSpecifies GDBFrontend websocket server's port.\n"); 84 | printf("\t--instance-user=USER, -u USER:\t\tSets the user that runs instances.\n"); 85 | printf("\t--instance-group=GROUP, -g GROUP:\tSets the group that runs instances.\n"); 86 | exit(0); 87 | } 88 | 89 | static void arg_handler_version(char* value) { 90 | printf("GDBFrontend: %s\n", GDBFRONTENDLIVE_GF_VERSION_STRING); 91 | exit(0); 92 | } 93 | 94 | static void arg_handler_host_address(char* addr) { 95 | gdbfrontendlive_host = addr; 96 | } 97 | 98 | static void arg_handler_bind_address(char* addr) { 99 | gdbfrontendlive_bind = addr; 100 | } 101 | 102 | static void arg_handler_ws_port(char* value) { 103 | gdbfrontendlive_ws_port = atoi(value); 104 | } 105 | 106 | static void arg_handler_instance_user(char* username) { 107 | gdbfrontendlive_verbose("Using user for instances: %s\n", username); 108 | 109 | gdbfrontendlive_instance_user_name = username; 110 | 111 | struct passwd* pwd = getpwnam(username); 112 | gdbfrontendlive_instance_user_uid = pwd->pw_uid; 113 | } 114 | 115 | static void arg_handler_instance_group(char* groupname) { 116 | gdbfrontendlive_verbose("Using group for instances: %s\n", groupname); 117 | 118 | gdbfrontendlive_instance_group_name = groupname; 119 | 120 | struct group* pwd = getgrnam(groupname); 121 | gdbfrontendlive_instance_group_gid = pwd->gr_gid; 122 | } -------------------------------------------------------------------------------- /src/uniqid.c: -------------------------------------------------------------------------------- 1 | /* 2 | * GDBFrontendLive is a server that creates sharable GDBFrontend instances and provides online IDEs. 3 | * 4 | * https://github.com/rohanrhu/gdb-frontend-live 5 | * https://oguzhaneroglu.com/projects/gdb-frontend-live/ 6 | * 7 | * Licensed under GNU/GPLv3 8 | * Copyright (C) 2020, Oğuzhan Eroğlu (https://oguzhaneroglu.com/) 9 | * 10 | */ 11 | 12 | #define _GNU_SOURCE 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "../include/uniqid.h" 22 | 23 | extern char* gdbfrontendlive_uniqid() { 24 | uuid_t uuid; 25 | char* uuid_str = malloc(UUID_STR_LEN); 26 | 27 | uuid_generate_random(uuid); 28 | uuid_unparse_lower(uuid, uuid_str); 29 | uuid_unparse(uuid, uuid_str); 30 | 31 | return uuid_str; 32 | } -------------------------------------------------------------------------------- /src/util.c: -------------------------------------------------------------------------------- 1 | /* 2 | * GDBFrontendLive is a server that creates sharable GDBFrontend instances and provides online IDEs. 3 | * 4 | * https://github.com/rohanrhu/gdb-frontend-live 5 | * https://oguzhaneroglu.com/projects/gdb-frontend-live/ 6 | * 7 | * Licensed under GNU/GPLv3 8 | * Copyright (C) 2020, Oğuzhan Eroğlu (https://oguzhaneroglu.com/) 9 | * 10 | */ 11 | 12 | #define _GNU_SOURCE 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | static int is_verbose = 1; 22 | 23 | extern void gdbfrontendlive_verbose(const char* format, ...) { 24 | if (!is_verbose) { 25 | return; 26 | } 27 | 28 | va_list args; 29 | va_start(args, format); 30 | vfprintf(stdout, format, args); 31 | va_end(args); 32 | } 33 | 34 | extern void gdbfrontendlive_set_verbose(int _is_verbose) { 35 | is_verbose = _is_verbose; 36 | } 37 | 38 | extern char* gdbfrontendlive_util_base64_encode(char* str) { 39 | unsigned int str_len = strlen(str); 40 | 41 | unsigned int encoded_size = 4 * ceil(((double)str_len / 3)); 42 | encoded_size = encoded_size + (encoded_size % 4); 43 | 44 | char* buffer = malloc(encoded_size+1); 45 | buffer[encoded_size] = '\0'; 46 | 47 | FILE* buff_stream = fmemopen(buffer, encoded_size+1, "w"); 48 | 49 | BIO *bio; 50 | BIO *b64; 51 | 52 | b64 = BIO_new(BIO_f_base64()); 53 | bio = BIO_new_fp(buff_stream, BIO_NOCLOSE); 54 | BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); 55 | BIO_push(b64, bio); 56 | BIO_write(b64, str, str_len); 57 | BIO_flush(b64); 58 | 59 | fclose(buff_stream); 60 | 61 | return buffer; 62 | } 63 | 64 | extern char* gdbfrontendlive_util_base64_decode(char* str) { 65 | unsigned int str_len = strlen(str); 66 | 67 | unsigned int decoded_size = 3 * ceil(str_len / 4); 68 | decoded_size = decoded_size - ((str[str_len-1] == '=') + (str[str_len-2] == '=')); 69 | 70 | char* buffer = malloc(decoded_size+1); 71 | buffer[decoded_size] = '\0'; 72 | 73 | FILE* str_stream = fmemopen(str, str_len, "r"); 74 | 75 | BIO *b64; 76 | BIO *bio; 77 | 78 | b64 = BIO_new(BIO_f_base64()); 79 | bio = BIO_new_fp(str_stream, BIO_NOCLOSE); 80 | bio = BIO_push(b64, bio); 81 | BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL); 82 | buffer[BIO_read(bio, buffer, str_len)] = '\0'; 83 | BIO_free_all(b64); 84 | 85 | fclose(str_stream); 86 | 87 | return buffer; 88 | } -------------------------------------------------------------------------------- /src/websocket.c: -------------------------------------------------------------------------------- 1 | /* 2 | * GDBFrontendLive is a server that creates sharable GDBFrontend instances and provides online IDEs. 3 | * 4 | * https://github.com/rohanrhu/gdb-frontend-live 5 | * https://oguzhaneroglu.com/projects/gdb-frontend-live/ 6 | * 7 | * Licensed under GNU/GPLv3 8 | * Copyright (C) 2020, Oğuzhan Eroğlu (https://oguzhaneroglu.com/) 9 | * 10 | */ 11 | 12 | #define _GNU_SOURCE 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "../lib/jsonic/jsonic.h" 28 | 29 | #include "../include/websocket.h" 30 | 31 | #include "../include/util.h" 32 | #include "../include/instance.h" 33 | 34 | static void sigabrt_handler() { 35 | printf("SIGABRT received."); 36 | } 37 | 38 | gdbfrontendlive_websocket_t* gdbfrontendlive_websocket_init(int port) { 39 | gdbfrontendlive_websocket_t* ws = malloc(sizeof(gdbfrontendlive_websocket_t)); 40 | ws->port = port; 41 | ws->host_address = NULL; 42 | ws->bind_address = NULL; 43 | 44 | return ws; 45 | } 46 | 47 | void gdbfrontendlive_websocket_listen(gdbfrontendlive_websocket_t* ws) { 48 | sigaction(SIGPIPE, &(struct sigaction){broken_pipe_handler}, NULL); 49 | sigaction(SIGABRT, &(struct sigaction){sigabrt_handler}, NULL); 50 | 51 | int server_socket; 52 | int client_socket; 53 | int client_addr_len; 54 | 55 | struct sockaddr_in serv_addr; 56 | struct sockaddr_in cli_addr; 57 | 58 | server_socket = socket(AF_INET, SOCK_STREAM, 0); 59 | 60 | if (server_socket < 0) { 61 | perror("Socket error"); 62 | exit(1); 63 | } 64 | 65 | setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int)); 66 | 67 | memset(&serv_addr, 0, sizeof(serv_addr)); 68 | 69 | serv_addr.sin_family = AF_INET; 70 | serv_addr.sin_addr.s_addr = INADDR_ANY; 71 | serv_addr.sin_port = htons(ws->port); 72 | 73 | if (ws->bind_address) { 74 | serv_addr.sin_addr.s_addr = inet_addr(ws->bind_address); 75 | } 76 | 77 | if (bind(server_socket, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) { 78 | perror("Bind error."); 79 | exit(1); 80 | } 81 | 82 | listen(server_socket, 10); 83 | client_addr_len = sizeof(cli_addr); 84 | 85 | gdbfrontendlive_websocket_clients_t* clients = NULL; 86 | 87 | ws->clients = clients; 88 | 89 | gdbfrontendlive_verbose("Server is listening from 0.0.0.0:%d\n", ws->port); 90 | 91 | printf("\033[32mOpen gdb-frontend-live-client/index.html and share gdb-frontend-live-client directory.\033[0m\n"); 92 | 93 | pthread_t client_thread; 94 | 95 | char str_addr[INET6_ADDRSTRLEN+1]; 96 | 97 | gdbfrontendlive_websocket_clients_t* client = NULL; 98 | gdbfrontendlive_websocket_clients_t* current_client = NULL; 99 | 100 | for (;;) { 101 | client_socket = accept(server_socket, (struct sockaddr *) &cli_addr, &client_addr_len); 102 | if (client_socket < 0) { 103 | perror("Accept error"); 104 | exit(1); 105 | } 106 | 107 | inet_ntop(AF_INET, (void*)&cli_addr.sin_addr, str_addr, INET_ADDRSTRLEN); 108 | 109 | gdbfrontendlive_verbose("New client: %s\n", str_addr); 110 | 111 | client = gdbfrontendlive_websocket_client_init(); 112 | client->ws = ws; 113 | client->server_socket = server_socket; 114 | client->is_host = 0; 115 | client->instance = NULL; 116 | client->socket = client_socket; 117 | client->address = cli_addr.sin_addr.s_addr; 118 | 119 | if (!clients) { 120 | clients = client; 121 | } else { 122 | client->prev = current_client; 123 | current_client->next = client; 124 | } 125 | 126 | current_client = client; 127 | 128 | pthread_create( 129 | &client_thread, 130 | NULL, 131 | (void *) &client_handler, 132 | (void *) client 133 | ); 134 | 135 | pthread_detach(client_thread); 136 | } 137 | } 138 | 139 | static void client_handler(gdbfrontendlive_websocket_clients_t* client) { 140 | sigaction(SIGPIPE, &(struct sigaction){broken_pipe_handler}, NULL); 141 | receive_http_packet(client); 142 | } 143 | 144 | static void receive_http_packet(gdbfrontendlive_websocket_clients_t* client) { 145 | char str_addr[INET6_ADDRSTRLEN+1]; 146 | inet_ntop(AF_INET, (void*)&client->address, str_addr, INET_ADDRSTRLEN); 147 | 148 | ssize_t result; 149 | 150 | int is_cr = 0; 151 | int is_lf = 0; 152 | 153 | char header_buff[HTTP_HEADER_BUFF_SIZE+1]; 154 | char prop_buff[HTTP_PROP_BUFF_SIZE+1]; 155 | char val_buff[HTTP_PROP_BUFF_SIZE+1]; 156 | 157 | int header_buff_i = 0; 158 | int prop_buff_i = 0; 159 | int val_buff_i = 0; 160 | 161 | enum GDBFRONTEND_WEBSOCKET_HTTP_HEADER_PARSER_STATE 162 | parser_state = GDBFRONTEND_WEBSOCKET_HTTP_HEADER_PARSER_STATE_METHOD; 163 | 164 | char byte; 165 | 166 | RECEIVE_PACKET: 167 | 168 | result = recv(client->socket, &byte, 1, MSG_WAITALL); 169 | 170 | if (!result) { 171 | gdbfrontendlive_verbose("Client disconnected: %s\n", str_addr); 172 | return; 173 | } 174 | 175 | if (parser_state == GDBFRONTEND_WEBSOCKET_HTTP_HEADER_PARSER_STATE_METHOD) { 176 | if (!is_cr) { 177 | if (byte == '\r') { 178 | is_cr = 1; 179 | } 180 | } else { 181 | if (byte == '\n') { 182 | parser_state = GDBFRONTEND_WEBSOCKET_HTTP_HEADER_PARSER_STATE_PROP; 183 | goto RECEIVE_PACKET; 184 | } else { 185 | close(client->socket); 186 | return; 187 | } 188 | } 189 | 190 | *(header_buff+(header_buff_i++)) = byte; 191 | 192 | if (!is_lf) { 193 | goto RECEIVE_PACKET; 194 | } 195 | 196 | is_lf = 0; 197 | 198 | const char* expected_header = "GET / HTTP/1.1"; 199 | 200 | if (strncmp(header_buff, expected_header, sizeof("GET / HTTP/1.1")-1) == 0) { 201 | goto RECEIVE_PACKET; 202 | } else { 203 | close(client->socket); 204 | return; 205 | } 206 | 207 | goto RECEIVE_PACKET; 208 | } else if (parser_state == GDBFRONTEND_WEBSOCKET_HTTP_HEADER_PARSER_STATE_PROP) { 209 | if (byte == '\r') { 210 | parser_state = GDBFRONTEND_WEBSOCKET_HTTP_HEADER_PARSER_STATE_END; 211 | } if (byte != ':') { 212 | *(prop_buff+(prop_buff_i++)) = byte; 213 | } else { 214 | parser_state = GDBFRONTEND_WEBSOCKET_HTTP_HEADER_PARSER_STATE_SPACE; 215 | *(prop_buff+(prop_buff_i)) = '\0'; 216 | prop_buff_i = 0; 217 | } 218 | } else if (parser_state == GDBFRONTEND_WEBSOCKET_HTTP_HEADER_PARSER_STATE_SPACE) { 219 | if (byte != ' ') { 220 | close(client->socket); 221 | return; 222 | } else { 223 | parser_state = GDBFRONTEND_WEBSOCKET_HTTP_HEADER_PARSER_STATE_VAL; 224 | } 225 | } else if (parser_state == GDBFRONTEND_WEBSOCKET_HTTP_HEADER_PARSER_STATE_VAL) { 226 | if (byte == '\r') { 227 | parser_state = GDBFRONTEND_WEBSOCKET_HTTP_HEADER_PARSER_STATE_CR; 228 | *(val_buff+(val_buff_i)) = '\0'; 229 | val_buff_i = 0; 230 | } else { 231 | *(val_buff+(val_buff_i++)) = byte; 232 | } 233 | } else if (parser_state == GDBFRONTEND_WEBSOCKET_HTTP_HEADER_PARSER_STATE_CR) { 234 | if (byte == '\n') { 235 | parser_state = GDBFRONTEND_WEBSOCKET_HTTP_HEADER_PARSER_STATE_PROP; 236 | 237 | if (strcmp(prop_buff, "Sec-WebSocket-Key") == 0) { 238 | int len = strlen(val_buff); 239 | client->ws_key = malloc(len+1); 240 | strcpy(client->ws_key, val_buff); 241 | } 242 | } else { 243 | close(client->socket); 244 | return; 245 | } 246 | } else if (parser_state == GDBFRONTEND_WEBSOCKET_HTTP_HEADER_PARSER_STATE_END) { 247 | if (byte == '\n') { 248 | char response_buf[500]; 249 | 250 | char concated[100]; 251 | unsigned char hash[SHA_DIGEST_LENGTH+1]; 252 | char* accept; 253 | 254 | sprintf(concated, "%s%s", client->ws_key, GDBFRONTENDLIVE_WEBSOCKET_GUID); 255 | 256 | hash[SHA_DIGEST_LENGTH] = '\0'; 257 | 258 | SHA1(concated, strlen(concated), hash); 259 | 260 | accept = gdbfrontendlive_util_base64_encode(hash); 261 | 262 | sprintf(response_buf, "HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: %s\r\nCompression: None\r\n\r\n", accept); 263 | 264 | send(client->socket, response_buf, strlen(response_buf), 0); 265 | 266 | goto RECEIVE_PACKET_WS; 267 | } 268 | } 269 | 270 | goto RECEIVE_PACKET; 271 | 272 | RECEIVE_PACKET_WS: 273 | 274 | receive_ws_packet(client); 275 | } 276 | 277 | static void receive_ws_packet(gdbfrontendlive_websocket_clients_t* client) { 278 | char str_addr[INET6_ADDRSTRLEN+1]; 279 | inet_ntop(AF_INET, (void*)&client->address, str_addr, INET_ADDRSTRLEN); 280 | 281 | ssize_t result; 282 | 283 | uint16_t header0_16; 284 | uint64_t plen; 285 | uint16_t plen16; 286 | uint16_t plen64; 287 | uint8_t opcode; 288 | uint8_t is_masked; 289 | unsigned char mkey[4]; 290 | 291 | char* req = NULL; 292 | char* res = NULL; 293 | 294 | RECEIVE_FRAME: 295 | 296 | result = recv(client->socket, &header0_16, 2, MSG_WAITALL); 297 | if (!result) { 298 | client_disconnected(client); 299 | return; 300 | } 301 | 302 | opcode = ((uint8_t)header0_16) & 0b00001111; 303 | 304 | if (opcode == 8) { 305 | client_disconnected(client); 306 | return; 307 | } 308 | 309 | is_masked = (*(((uint8_t*)(&header0_16))+1)) & -128; 310 | plen = (*(((uint8_t*)(&header0_16))+1)) & 127; 311 | 312 | if (plen == 126) { 313 | result = recv(client->socket, &plen16, 2, MSG_WAITALL); 314 | if (!result) { 315 | client_disconnected(client); 316 | return; 317 | } 318 | 319 | plen = ntohs(plen16); 320 | } else if (plen == 127) { 321 | result = recv(client->socket, &plen64, 8, MSG_WAITALL); 322 | if (!result) { 323 | client_disconnected(client); 324 | return; 325 | } 326 | 327 | plen = ntohs(plen64); 328 | } 329 | 330 | if (is_masked) { 331 | result = recv(client->socket, mkey, 4, MSG_WAITALL); 332 | if (!result) { 333 | client_disconnected(client); 334 | return; 335 | } 336 | } 337 | 338 | req = malloc(plen+1); 339 | req[plen] = '\0'; 340 | 341 | result = recv(client->socket, req, plen, MSG_WAITALL); 342 | if (!result) { 343 | client_disconnected(client); 344 | return; 345 | } 346 | 347 | if (is_masked) { 348 | for (int i=0; i < plen; i++) { 349 | req[i] = req[i] ^ mkey[i%4]; 350 | } 351 | } 352 | 353 | gdbfrontendlive_verbose("Raw Message: %s\n", req); 354 | 355 | jsonic_node_t* root = jsonic_get_root(req); 356 | jsonic_node_t* action = jsonic_object_get(req, root, "action"); 357 | 358 | if (action->type == JSONIC_NONE) { 359 | goto RECEIVE_FRAME; 360 | } 361 | 362 | if (strcmp(action->val, "instance_create") == 0) { 363 | client->is_host = 1; 364 | client->instance = gdbfrontendlive_instance_create(); 365 | client->instance->host_address = client->ws->host_address; 366 | client->instance->bind_address = client->ws->bind_address; 367 | client->instance->client = client; 368 | 369 | gdbfrontendlive_instance_run(client->instance); 370 | 371 | res = malloc(500); 372 | 373 | sprintf( 374 | res, 375 | "{" 376 | "\"ok\": true," 377 | "\"event\": \"instance_create_ret\"," 378 | "\"instance\": {" 379 | "\"http_port\": %u," 380 | "\"id\": \"%s\"" 381 | "}" 382 | "}", 383 | client->instance->http_port, 384 | client->instance->id 385 | ); 386 | 387 | send_ws_packet(client, res); 388 | } else if (strcmp(action->val, "instance_get") == 0) { 389 | jsonic_node_t* id = jsonic_object_get(req, root, "id"); 390 | 391 | if (id->type == JSONIC_NONE) { 392 | goto RECEIVE_FRAME; 393 | } 394 | 395 | client->instance = gdbfrontendlive_instance_getby_id(id->val); 396 | 397 | res = malloc(500); 398 | 399 | if (client->instance) { 400 | sprintf( 401 | res, 402 | "{" 403 | "\"ok\": true," 404 | "\"event\": \"instance_get_ret\"," 405 | "\"instance\": {" 406 | "\"http_port\": %u," 407 | "\"id\": \"%s\"" 408 | "}" 409 | "}", 410 | client->instance->http_port, 411 | client->instance->id 412 | ); 413 | } else { 414 | sprintf( 415 | res, 416 | "{" 417 | "\"ok\": true," 418 | "\"event\": \"instance_get_ret\"," 419 | "\"instance\": false" 420 | "}" 421 | ); 422 | } 423 | 424 | send_ws_packet(client, res); 425 | } else if (strcmp(action->val, "ping") == 0) { 426 | res = malloc(500); 427 | 428 | sprintf( 429 | res, 430 | "{" 431 | "\"ok\": true," 432 | "\"event\": \"pong\"" 433 | "}" 434 | ); 435 | 436 | send_ws_packet(client, res); 437 | } 438 | 439 | if (req) { 440 | free(req); 441 | req = NULL; 442 | } 443 | 444 | if (res) { 445 | free(res); 446 | res = NULL; 447 | } 448 | 449 | goto RECEIVE_FRAME; 450 | } 451 | 452 | static void client_disconnected(gdbfrontendlive_websocket_clients_t* client) { 453 | char str_addr[INET6_ADDRSTRLEN+1]; 454 | inet_ntop(AF_INET, (void*)&client->address, str_addr, INET_ADDRSTRLEN); 455 | 456 | gdbfrontendlive_verbose("Client disconnected: %s\n", str_addr); 457 | 458 | if (client) { 459 | gdbfrontendlive_websocket_client_free(client); 460 | client = NULL; 461 | } 462 | } 463 | 464 | static void send_ws_packet(gdbfrontendlive_websocket_clients_t* client, char* message) { 465 | unsigned int message_len = strlen(message); 466 | 467 | if (message_len < 126) { 468 | gdbfrontendlive_websocket_packet_frame_len8_t message_frame; 469 | message_frame.fin_rsv_opcode = 0b10000001; 470 | message_frame.mlen8 = message_len; 471 | 472 | send(client->socket, &message_frame, sizeof(gdbfrontendlive_websocket_packet_frame_len8_t), 0); 473 | } else if (message_len < (1 << 16)) { 474 | gdbfrontendlive_websocket_packet_frame_len16_t message_frame; 475 | message_frame.fin_rsv_opcode = 0b10000001; 476 | message_frame.mlen8 = 126; 477 | message_frame.len16 = message_len; 478 | 479 | send(client->socket, &message_frame, sizeof(gdbfrontendlive_websocket_packet_frame_len16_t), 0); 480 | } else { 481 | gdbfrontendlive_websocket_packet_frame_len64_t message_frame; 482 | message_frame.fin_rsv_opcode = 0b10000001; 483 | message_frame.mlen8 = 127; 484 | message_frame.len64 = message_len; 485 | 486 | send(client->socket, &message_frame, sizeof(gdbfrontendlive_websocket_packet_frame_len64_t), 0); 487 | } 488 | 489 | send(client->socket, message, strlen(message), 0); 490 | } 491 | 492 | extern gdbfrontendlive_websocket_clients_t* gdbfrontendlive_websocket_client_init() { 493 | gdbfrontendlive_websocket_clients_t* client = malloc(sizeof(gdbfrontendlive_websocket_clients_t)); 494 | client->socket = 0; 495 | client->ws_key = NULL; 496 | client->address = 0; 497 | client->next = NULL; 498 | client->prev = NULL; 499 | 500 | return client; 501 | } 502 | 503 | extern void gdbfrontendlive_websocket_client_free(gdbfrontendlive_websocket_clients_t* client) { 504 | if (client->next) { 505 | client->next->prev = client->prev; 506 | } 507 | 508 | if (client->prev) { 509 | client->prev->next = client->next; 510 | } 511 | 512 | if (client->is_host && client->instance) { 513 | if (client->instance) { 514 | gdbfrontendlive_instance_destroy(client->instance); 515 | client->instance = NULL; 516 | } 517 | } 518 | 519 | if (client->ws_key != NULL) { 520 | free(client->ws_key); 521 | } 522 | 523 | free(client); 524 | } 525 | 526 | void gdbfrontendlive_websocket_free(gdbfrontendlive_websocket_t* ws) { 527 | free(ws); 528 | } 529 | 530 | void broken_pipe_handler(int sig) { 531 | gdbfrontendlive_verbose("Broken pipe.\n"); 532 | } -------------------------------------------------------------------------------- /template/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Welcome to GFLIVE! 3 | * GFLIVE is an online IDE and debugger powered by GDBFrontendLive and GDBFrontend. 4 | * 5 | * GDBFrontendLive and GDBFrontend both are open source projects and your contributions are welcome. 6 | * You can report issues or suggestions on Github: https://github.com/rohanrhu/gdb-frontend-live 7 | * 8 | * GDBFrontendLive may be useful especially for educational purposes and 9 | * you can share your session with the link on the top and debug together! 10 | * 11 | */ 12 | 13 | #include 14 | 15 | int main(int argc, char* argv[]) { 16 | printf("Hello World from GFLIVE!\n"); 17 | 18 | return 0; 19 | } 20 | 21 | /* 22 | * To start your ap, just click to "bug button" on top left. 23 | */ --------------------------------------------------------------------------------